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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
cinderelly678
Frequent Visitor

DAX Measure Help: Counting Status Changes Over Time

I am having some trouble writing a measure which would count the number of times a status has changed for a particular item. My source is an SDC Type 2 table containing all history of status changes. 

 

I want to make a measure that ranks the count of status changes over time. In the sample data, the grouping is by Fruit, _Timestamp, _Operation, Consumable Status, and Status Change Date. I want to make a column called "Status Change Count" with the below output.

 

ellywinters_0-1691443560876.png

 

Could anyone help me out with the DAX to accomplish this? Thank you in advance for your help.

 

Attached is my sample data. 

 

Fruit_Timestamp_OperationConsumable StatusStatus Change Date
Apples8/8/2023 17:46DSpoiled Fruit - Discard8/8/2023 0:00
Apples8/7/2023 17:46UUndocked11/8/2022 0:00
Apples7/25/2023 17:49UUndocked11/8/2022 0:00
Apples5/31/2023 17:39UUndocked11/8/2022 0:00
Apples5/25/2023 17:38UUndocked11/8/2022 0:00
Apples5/22/2023 17:36UUndocked11/8/2022 0:00
Apples5/18/2023 17:39UUndocked11/8/2022 0:00
Apples3/17/2023 17:38UUndocked11/8/2022 0:00
Apples3/3/2023 17:33UUndocked11/8/2022 0:00
Apples2/1/2023 17:06UUndocked11/8/2022 0:00
Apples12/27/2022 17:07UUndocked11/8/2022 0:00
Apples12/6/2022 17:07UUndocked11/8/2022 0:00
Apples11/8/2022 17:07UUndocked11/8/2022 0:00
Apples10/28/2022 14:54DShipped to Store10/27/2022 0:00
Apples10/28/2022 14:54IShipped to Store10/27/2022 0:00
Apples10/27/2022 17:06DShipped to Store10/27/2022 0:00
Apples10/27/2022 17:06IShipped to Store10/27/2022 0:00
Apples10/27/2022 17:05IShipped to Store10/27/2022 0:00
Apples10/26/2022 17:06UPayment Received10/26/2022 0:00
Apples10/24/2022 17:06UPurchase Order Approved10/24/2022 0:00
Apples10/24/2022 17:05IPurchase Order Received10/24/2022 0:00
Oranges8/7/2023 17:46UUndocked11/8/2022 0:00
Oranges7/25/2023 17:49UUndocked11/8/2022 0:00
Oranges5/31/2023 17:39UUndocked11/8/2022 0:00
Oranges5/25/2023 17:38UUndocked11/8/2022 0:00
Oranges5/22/2023 17:36UUndocked11/8/2022 0:00
Oranges5/18/2023 17:39UUndocked11/8/2022 0:00
Oranges3/17/2023 17:38UUndocked11/8/2022 0:00
Oranges3/3/2023 17:33UUndocked11/8/2022 0:00
Oranges2/1/2023 17:06UUndocked11/8/2022 0:00
Oranges12/27/2022 17:07UUndocked11/8/2022 0:00
Oranges12/6/2022 17:07UUndocked11/8/2022 0:00
Oranges11/8/2022 17:07UUndocked11/8/2022 0:00
Oranges10/28/2022 14:54DShipped to Store10/27/2022 0:00
Oranges10/28/2022 14:54IShipped to Store10/27/2022 0:00
Oranges10/27/2022 17:06DShipped to Store10/27/2022 0:00
Oranges10/27/2022 17:06IShipped to Store10/27/2022 0:00
Oranges10/27/2022 17:05UShipped to Store10/27/2022 0:00
Oranges10/26/2022 17:06UPayment Received10/26/2022 0:00
Oranges10/24/2022 17:06UPurchase Order Approved10/24/2022 0:00
Oranges10/24/2022 17:05IPurchase Order Received10/24/2022 0:00
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@cinderelly678 Try:

Measure = 
    VAR __Fruit = MAX('Table'[Fruit])
    VAR __TS = MAX('Table'[Timestamp])
    VAR __Table = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'), [Fruit] = __Fruit && [Timestamp] <= __TS), "__Status", [Consumable Status]))
    VAR __Result = COUNTROWS(__Table)
RETURN
    __Result


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
cinderelly678
Frequent Visitor

@Greg_Deckler , thank you very much, that worked like a charm!

 

Now I have a secondary question. Let's say I wanted to iterate over the results of the Measure to flag when the measure has incremented by one over the previous value. How could I achieve that? 

 

 

@cinderelly678 That's Cthulhu. Cthulhu - Microsoft Fabric Community



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Oh goodness -- sweet post! Let me try to wrap my head around this.

 

I'll likely respond with questions soon.

 

Thank you so much for sharing @Greg_Deckler !

Greg_Deckler
Community Champion
Community Champion

@cinderelly678 Try:

Measure = 
    VAR __Fruit = MAX('Table'[Fruit])
    VAR __TS = MAX('Table'[Timestamp])
    VAR __Table = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'), [Fruit] = __Fruit && [Timestamp] <= __TS), "__Status", [Consumable Status]))
    VAR __Result = COUNTROWS(__Table)
RETURN
    __Result


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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