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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Nick1810
Frequent Visitor

Cumulative Count Per Month Unitl Some Condition

Hello!

 

I am trying to generate a COLUMN with the data in red, based on the table below.

What I am trying to get is the Acumulative Count of the consecutives "Yes" processes per Product until you get a "No", reading from the latest date to the oldest.

For example, in the case for Product "BBB" I begin from the latest date, which is 06/2022, and check ifthis date has a "Yes". In this case it has, so I count 1. Then, i check the next latest date, which is 05/2022. Since it also has a "Yes", I count 1 more. The same with 04/2022, so I count 1 more. Then, since the next latest date is 03/2022 has a "No", I stop counting. The cumulative count is 3, so that is the value I should reach in the column in red.

 

ProductProcess DateProcessed?CUMULATIVE CONSECUTIVE YES LAST PROCESSED MONTHS
AAA01-2022Yes0
AAA02-2022Yes0
AAA03-2022No0
AAA04-2022Yes0
AAA05-2022No0
AAA06-2022No0
BBB01-2022Yes3
BBB02-2022No3
BBB03-2022No3
BBB04-2022Yes3
BBB05-2022Yes3
BBB06-2022Yes3
CCC01-2022No1
CCC02-2022No1
CCC03-2022No1
CCC04-2022Yes1
CCC05-2022No1
CCC06-2022Yes1

 

Thanks!

 

Nicolás.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Nick1810 

please try

Acumulative Count =
VAR CurrentProductTable =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Product] ) )
VAR NoTable =
    FILTER ( CurrentProductTable, 'Table'[Processed?] = "No" )
VAR LastNoRecord =
    TOPN ( 1, NoTable, 'Table'[Process Date] )
VAR LastNoDate =
    MAXX ( LastNoRecord, 'Table'[Process Date] )
VAR YesTable =
    FILTER ( CurrentProductTable, 'Table'[Processed?] = "Yes" )
VAR YesAfterNoTable =
    FILTER ( YesTable, 'Table'[Process Date] > LastNoDate )
RETURN
    COUNTROWS ( YesAfterNoTable )

View solution in original post

3 REPLIES 3
besomebody20
Resolver I
Resolver I

Hi @Nick1810 ,

Please try this DAX Calculated Column to return the cumulative total you are looking for:

 

Cumulated Count Processed by Product = 
VAR _product = 'Sample Data'[Product]
VAR _productMaxYesProcessDate =
CALCULATE(
MAX('Sample Data'[Process Date]),
FILTER(
ALL('Sample Data'),
'Sample Data'[Product] = _product && 'Sample Data'[Processed?] = "Yes"
)
)

VAR _productMaxNoProcessDate =
CALCULATE(
MAX('Sample Data'[Process Date]),
FILTER(
ALL('Sample Data'),
'Sample Data'[Product] = _product && 'Sample Data'[Processed?] = "No"
)
)

VAR _count =
COUNTROWS(
CALCULATETABLE(
'Sample Data',
FILTER(
ALL('Sample Data'),
'Sample Data'[Product] = _product &&
'Sample Data'[Process Date] > _productMaxNoProcessDate &&
'Sample Data'[Process Date] <= _productMaxYesProcessDate
)
)
)

RETURN
COALESCE(_count, 0)
tamerj1
Super User
Super User

Hi @Nick1810 

please try

Acumulative Count =
VAR CurrentProductTable =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Product] ) )
VAR NoTable =
    FILTER ( CurrentProductTable, 'Table'[Processed?] = "No" )
VAR LastNoRecord =
    TOPN ( 1, NoTable, 'Table'[Process Date] )
VAR LastNoDate =
    MAXX ( LastNoRecord, 'Table'[Process Date] )
VAR YesTable =
    FILTER ( CurrentProductTable, 'Table'[Processed?] = "Yes" )
VAR YesAfterNoTable =
    FILTER ( YesTable, 'Table'[Process Date] > LastNoDate )
RETURN
    COUNTROWS ( YesAfterNoTable )

Genious!! Thankss

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.