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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
AlexisKMX
Frequent Visitor

Index Colum

Hey everyone!

 

I'm new at working with DAX functions and i am struggling with this. 

 

I want to create an index colum for the PASSED tests performed per week. I want that the index count starts over each start of a new week and also that it only takes into account the "PASSED" tests. 

 

Also, this table shows only data for 2022, but i have other tests performed in past years.

 

My idea is to create an slicer in Power BI that filters for Week Number and Year Number, and displays the information of the PASSED tests performed in the selected Week Number of the Year Number selected. 

 

AlexisKMX_0-1655059734125.png

I would appreciate any other new ideas to achieve this. Thanks people!

 

2 ACCEPTED SOLUTIONS
samdthompson
Memorable Member
Memorable Member

Hello. You will want to do that bit in PowerQuery since it will be less resource hungry. You are needing a rank by group. Broadly the approach is to Add the index, then group and add the index again. Take particular note of the  Added Custom row of code. this is where the magic happens. Do make sure you have the data sorted in whatever order best suits you ranking needs before you apply these steps.

 

The Code will be something along these lines:

 

let

.....

#"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 2, 1, Int64.Type),
#"Grouped Rows" = Table.Group(#"Added Index", {"DATE_DONE"}, {{"Table", each _, type table [WEEK=nullable text, DATE_DONE=nullable text, Index=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Table],"Index2",1)),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Index2"}, {"Custom.Index2"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Table"})
in
#"Removed Columns"

 

 

// if this is a solution please mark as such. Kudos always appreciated.

View solution in original post

tackytechtom
Super User
Super User

Hi @AlexisKMX ,

 

Agree a 100% with @samdthompson, do it in PQ!

 

If (due to some reasons) you can not do it in PQ, here a solution in DAX, anyway:

tomfox_0-1655062073548.png

 

 

Here the DAX code for a calculated column:

INDEX = 
IF (
    TestTable[State] = "PASSED", 
    RANKX ( 
        FILTER ( 
            'TestTable', 
            TestTable[State] = "PASSED" && 'TestTable'[WEEK] = EARLIER ( 'TestTable'[WEEK] )
        ),
        'TestTable'[Date Done],
        , ASC
        , DENSE
    ),
    BLANK()
)

 

I used the code snippet from here.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
AlexisKMX
Frequent Visitor

Thanks @tackytechtom and @samdthompson ! Both methods works for me! I just found a little bit more complicated the PQ way but I was able to make it work.

Thanks for your time.

tackytechtom
Super User
Super User

Hi @AlexisKMX ,

 

Agree a 100% with @samdthompson, do it in PQ!

 

If (due to some reasons) you can not do it in PQ, here a solution in DAX, anyway:

tomfox_0-1655062073548.png

 

 

Here the DAX code for a calculated column:

INDEX = 
IF (
    TestTable[State] = "PASSED", 
    RANKX ( 
        FILTER ( 
            'TestTable', 
            TestTable[State] = "PASSED" && 'TestTable'[WEEK] = EARLIER ( 'TestTable'[WEEK] )
        ),
        'TestTable'[Date Done],
        , ASC
        , DENSE
    ),
    BLANK()
)

 

I used the code snippet from here.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

samdthompson
Memorable Member
Memorable Member

Hello. You will want to do that bit in PowerQuery since it will be less resource hungry. You are needing a rank by group. Broadly the approach is to Add the index, then group and add the index again. Take particular note of the  Added Custom row of code. this is where the magic happens. Do make sure you have the data sorted in whatever order best suits you ranking needs before you apply these steps.

 

The Code will be something along these lines:

 

let

.....

#"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 2, 1, Int64.Type),
#"Grouped Rows" = Table.Group(#"Added Index", {"DATE_DONE"}, {{"Table", each _, type table [WEEK=nullable text, DATE_DONE=nullable text, Index=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Table],"Index2",1)),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Index2"}, {"Custom.Index2"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Table"})
in
#"Removed Columns"

 

 

// if this is a solution please mark as such. Kudos always appreciated.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors