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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
jt1999
Frequent Visitor

Index by 2 Variables in PowerQuery

Hello,

 

I am looking to index a very large data set based on 2 conditons. One condition is based on the date (month specifically, even though it is in short date format for the example provided) and by part number. I have found some close answers, but they do not give me exactly what I need. I know there are ways to do this in DAX, however for my purpose it makes more sense for me to do it in PowerQuery. 

 

Below is an example of what I am trying to do. 

 

DateIDIndex
1/1/2022ABC1
2/1/2022DEF1
1/1/2022ABC2
2/1/2022DEF2
3/1/2022ABC1
4/1/2022DEF1
5/1/2022ABC1
1/1/2022ABC3

 

There will be over 100 different "ID"'s and up to 12 months (will not need to carry over to next year). If anyone could point me in the right direction, that would be a great help. 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @jt1999 

 

I haven't thought of a good way to do this in PowerQuery yet. If you use DAX you can try the following. You need to add a column index in PowerQuery first.

Column:

Index2 =
CALCULATE (
    COUNT ( 'Table'[ID] ),
    FILTER (
        ALL ( 'Table' ),
        [Date] = EARLIER ( 'Table'[Date] )
            && [ID] = EARLIER ( 'Table'[ID] )
            && [Index] <= EARLIER ( 'Table'[Index] )
    )
)

vzhangti_0-1650868549767.png

Hope this helps you.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
jt1999
Frequent Visitor

Thank you! @v-zhangti

 

This definitely does help. I suppose the only reason I would prefer to have it in PowerQuery is so I can work with index2 in the transform data tab, but I still should be able to accomplish what I need to with DAX. 

 

Plus, I am relativley new to PowerBI so I think being able to work in PowerQuery is more comfortable to me as opposed to DAX, but I gotta start somewhere!

v-zhangti
Community Support
Community Support

Hi, @jt1999 

 

I haven't thought of a good way to do this in PowerQuery yet. If you use DAX you can try the following. You need to add a column index in PowerQuery first.

Column:

Index2 =
CALCULATE (
    COUNT ( 'Table'[ID] ),
    FILTER (
        ALL ( 'Table' ),
        [Date] = EARLIER ( 'Table'[Date] )
            && [ID] = EARLIER ( 'Table'[ID] )
            && [Index] <= EARLIER ( 'Table'[Index] )
    )
)

vzhangti_0-1650868549767.png

Hope this helps you.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.