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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Natsnebki
Frequent Visitor

Running count with changing categories

Hi,

 

I try to get the following matrix out of this data:

Data:

DateCATStatus
22/01/01aYES
22/01/01cYES
22/01/03bYES
22/01/05cNO
22/01/08cYES
22/01/10aNO
22/01/10bNO

 

As you can see the status may change over time.

Wanted matrix:

DatesYESNOTotal
22/01/01202
22/01/02202
22/01/03303
22/01/04303
22/01/05213
22/01/06213
22/01/07213
22/01/08303
22/01/09303
22/01/10123

 

So the count of the status by day., also for the dates there is no data.

 

I used a related table (DATESINTABLE) with all dates between the MIN date and the Max date from the source, and with the folllowing measure I got this result:

Measure:

Running Dcount status by dimdate =
CALCULATE (
   DISTINCTCOUNT( 'Table'[CAT]),
    FILTER (
        ALLEXCEPT('Table', 'Table'[Status]),
        'Table'[Date]<= MAX(DATESINTABLE[Dates])
    )
)
 
MATRIX:
Natsnebki_0-1668514745786.png

So I think i'm almost there, but maybe not. 

 

Any help would be much appreciated

Thank you

 

1 ACCEPTED SOLUTION
Natsnebki
Frequent Visitor

I solved it by creating a table with all dates between min date and max date, merge this full outer, sort by category and date and fill down all nulls in Status. 

View solution in original post

5 REPLIES 5
Natsnebki
Frequent Visitor

I solved it by creating a table with all dates between min date and max date, merge this full outer, sort by category and date and fill down all nulls in Status. 

FreemanZ
Super User
Super User

Hi @Natsnebki 

try to create a new table with the code below:

Table = 
VAR Table1 = 
	ADDCOLUMNS(
	    SUMMARIZE(
	        TableName, 
	        TableName[Date]
	    ),
	    "YES",
	    CALCULATE(
	        COUNTROWS(
	            FILTER(
	                TableName, 
	                TableName[Status] = "YES"
	            )
	        )    
	    ),
	    "NO",
	    CALCULATE(
	        COUNTROWS(
	            FILTER(
	                TableName, 
	                TableName[Status] = "No"
	            )
	        )    
	    )
	)
VAR Table2 =
	ADDCOLUMNS(
		Table1,
		"Total",
		[Yes]+[No]
		
	)
RETURN 
	Table2

 

i tried and it works like this:

FreemanZ_0-1669182450736.png

your dataset:

FreemanZ_1-1669182473182.png

 

Jayee
Responsive Resident
Responsive Resident

Hi @Natsnebki ,

 

Please refer to this Page for details about how to calculate running totals in DAX.

daXtreme
Solution Sage
Solution Sage

ALLEXCEPT does not work the way you think it does. Please refer to https://dax.guide/allexcept for details. 

 

Here's the code you'd most likely want:

// Base measure
# CATs = DISTINCTCOUNT( 'Table'[CAT] )

// Base measure - RT
# CATs RT =
var LastVisibleDate = MAX( Dates[Date] )
var Result =
    CALCULATE(
        // YOu add 0 to be able to see
        // also the rows which would
        // have BLANKs.
        [# CATs] + 0,
        Dates[Date] <= LastVisibleDate,
        REMOVEFILTERS( Dates )
    )
return
    Result

 

Thank you for your suggestion. This measure adds 0's in my matrix instead of blanks, but the count is still the same, and not what i need. The fact that a cat has a changing status, is not counted correctly. I hope I'm clear

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.