Posts

Showing posts from June, 2020

Donate

How To Combine Specific Columns Per Table Using DAX Union

Guys, Here's a DAX formula that will perform union of two tables given their specific column names in Power BI. The trick is to use SELECTCOLUMNS () function for each table. Countries = UNION ( SELECTCOLUMNS ( 'Main Location' , "Countries" , 'Main Location' [Countries] ), SELECTCOLUMNS ( 'Sales' , "Countries" , 'Sales' [Countries] ) )

Line Chart X-Axis Month Values Not Sorting Correctly In Power BI LineChart

Image
Gents, Today, I had an issue with month values in my line chart visual not sorting correctly. The month values were plainly text in type and it seems the line chart does not recognize it's order. In order for these to work, I need to create a month column to explicitly include the year and retrieve the value using DateValue() function. If the measure is added in the visual, set the proper date format in Power BI desktop for the line chart to recognize the proper sequence. MonthYear = var monthName = TRIM (GrossProfitTrend[MonthName]) Return SWITCH(monthName, "Jan" , DATEVALUE( MONTH ( DATE ( YEAR (NOW()), 1 , 1 )) & " " & YEAR (NOW())) , "Feb" , DATEVALUE( MONTH ( DATE ( YEAR (NOW()), 2 , 1 )) & " " & YEAR (NOW())) , "Mar" , DATEVALUE( MONTH ( DATE ( YEAR (NOW()), 3 , 1 )) & " " & YEAR (NOW())) , "Apr" , DATEVALUE( MONTH ( DATE ( YEAR (NOW()), 4 , 1 )...

Add Row Number Dynamically To Query Results In T-SQL

Image
Aloha fellow developers! I have this scenario wherein I need to display row numbers in my result set given that the rows don't have a ID column and each row number represents the month number of a specific month. SELECT A.fsyear_num as 'Fiscal Year' , [MonthName] FROM CTE_GrossProfit_SalesByClass_Current_FSYear A I know that row number is the solution but I need to tweak this to handle my requirement. After reading the forums and docs, I found out that adding a select statement with COUNT() inside the Over By clause is the solution. SELECT A.fsyear_num as 'Fiscal Year' , ROW_NUMBER() Over( Order BY ( Select Count ( * ))) AS MonthNum, [MonthName] FROM CTE_GrossProfit_SalesByClass_Current_FSYear A ORDER BY MonthNum ASC

Donate