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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JofrainVisda
Advocate I
Advocate I

Row Index

Hi friends,

I would like to achieve this using DAX. I have achieved this actually credits one of our friends here who provided the correct DAX.
But I needed to change something.
In the image is what I want to get. I already got to create a row sequence if they have the same value of Column 1 using the DAX below. Now I want to add a parameter to put a sequence based on the Column 2.

JofrainVisda_0-1708079850790.png

 

Column Row =

ROWNUMBER(
    SUMMARIZE(
        ALLSELECTED( 'vw_AssignedChecklist2 (2)')
        , 'vw_AssignedChecklist2 (2)'[Column]
        , 'vw_AssignedChecklist2 (2)'[Index]
    )
    , ORDERBY('vw_AssignedChecklist2 (2)'[Index])
    , DEFAULT
    , PARTITIONBY('vw_AssignedChecklist2 (2)'[Column] )
)
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@JofrainVisda Not sure why you need to get so complicated with your original formula, you can do the same thing like this:

Column Row Easy = 
    VAR __Index = [Index]
    VAR __Mod = MOD([Index], 3)
    VAR __Table = ADDCOLUMNS('vw_AssignedChecklist2 (2)', "__ModColumn", MOD([Index], 3))
    VAR __Return = COUNTROWS(FILTER( __Table, [__ModColumn] = __Mod && [Index] <= __Index))
RETURN
    __Return

For the other one, you can do this:

Seq Column 2 = 
    VAR __Value = [Column2]
    VAR __Values = DISTINCT('vw_AssignedChecklist2 (2)'[Column2])
    VAR __Path = CONCATENATEX(__Values, [Column2], "|",[Index])
    VAR __Count = COUNTROWS(__Values)
    VAR __Table = 
        ADDCOLUMNS(
            GENERATESERIES(1, __Count, 1),
            "__Item", PATHITEM( __Path, [Value], TEXT)
        )   
    VAR __Return = MAXX(FILTER(__Table, [__Item] = __Value), [Value])
RETURN
    __Return

PBIX is attached below signature.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@JofrainVisda Not sure why you need to get so complicated with your original formula, you can do the same thing like this:

Column Row Easy = 
    VAR __Index = [Index]
    VAR __Mod = MOD([Index], 3)
    VAR __Table = ADDCOLUMNS('vw_AssignedChecklist2 (2)', "__ModColumn", MOD([Index], 3))
    VAR __Return = COUNTROWS(FILTER( __Table, [__ModColumn] = __Mod && [Index] <= __Index))
RETURN
    __Return

For the other one, you can do this:

Seq Column 2 = 
    VAR __Value = [Column2]
    VAR __Values = DISTINCT('vw_AssignedChecklist2 (2)'[Column2])
    VAR __Path = CONCATENATEX(__Values, [Column2], "|",[Index])
    VAR __Count = COUNTROWS(__Values)
    VAR __Table = 
        ADDCOLUMNS(
            GENERATESERIES(1, __Count, 1),
            "__Item", PATHITEM( __Path, [Value], TEXT)
        )   
    VAR __Return = MAXX(FILTER(__Table, [__Item] = __Value), [Value])
RETURN
    __Return

PBIX is attached below signature.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
AmiraBedh
Resident Rockstar
Resident Rockstar

Try :

Column Row = 
ROWNUMBER(
    SUMMARIZE(
        ALLSELECTED('vw_AssignedChecklist2 (2)'),
        'vw_AssignedChecklist2 (2)'[Column 2],  // Partition by Column 2
        'vw_AssignedChecklist2 (2)'[Column 1],  // Then by Column 1
        "Index", 'vw_AssignedChecklist2 (2)'[Index]  // Include Index for ordering within partitions
    ),
    ORDERBY('vw_AssignedChecklist2 (2)'[Column 2], ASC, 
            'vw_AssignedChecklist2 (2)'[Column 1], ASC,
            'vw_AssignedChecklist2 (2)'[Index], ASC),  // Order by Column 2, then Column 1, then Index
    DEFAULT,
    PARTITIONBY('vw_AssignedChecklist2 (2)'[Column 2], 
                'vw_AssignedChecklist2 (2)'[Column 1])  // Partition by both Column 2 and Column 1
)

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.