Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
luccaguimaraes
Frequent Visitor

How to create a Row Column in DAX

Hi,

 

I need to create a column that contains the row number, exactly like the red numbers on the print below:

 

*It has to be on DAX because It is a calculated table from M code

*It will always have 4 rows
*I do not intend to rank the rows by the name, only by normal order

 

luccaguimaraes_2-1650663211616.png

 

Could someone help me?

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is one way to do it with DAX (without RANKX). Just create a DAX table with the expression below.

 

MonthTable =
VAR fourmonthsago =
EOMONTH( TODAY(), -4 )
VAR monthdates =
ADDCOLUMNS(
GENERATESERIES( 1, 4, 1 ),
"Mes/Ano", FORMAT( EOMONTH( fourmonthsago, [Value] ), "mmm/yy" )
)
RETURN
monthdates

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Employee
Employee

Here is one way to do it with DAX (without RANKX). Just create a DAX table with the expression below.

 

MonthTable =
VAR fourmonthsago =
EOMONTH( TODAY(), -4 )
VAR monthdates =
ADDCOLUMNS(
GENERATESERIES( 1, 4, 1 ),
"Mes/Ano", FORMAT( EOMONTH( fourmonthsago, [Value] ), "mmm/yy" )
)
RETURN
monthdates

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Employee
Employee

If you just need a 4-row/2-column table, you could just use the DATATABLE function.

DATATABLE – DAX Guide

 

Or, if it needs to be dynamic and show the last 4 months, you could calculate a Date column from the month/year and then use RANKX on that to get 1-4.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.