This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
Greetings,
How can I create a colmn in DAX for running count of IDs, sorted descending by the date. For example:
| ID | date | RUNNING COUNT | |||
| 111 | 1/1/2023 | 1 | |||
| 222 | 1/1/2020 | 1 | |||
| 888 | 1/1/2022 | 1 | |||
| 222 | 1/1/2018 | 3 | |||
| 222 | 1/1/2019 | 2 | |||
| 111 | 1/1/2019 | 2 | |||
| 888 | 1/1/2020 | 2 |
Solved! Go to Solution.
Hi,
Write this calculated column formula
Running count = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[date]>=EARLIER(Data[date])))
Hope this helps.
Hi,
Write this calculated column formula
Running count = CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[date]>=EARLIER(Data[date])))
Hope this helps.
@Ashish_Mathur The purpose of the running count is because I want to get the company name of the previous record for each employee. Would you please help me create the calculated column to get the previous company? below is an example:
| ID | date | RUNNING COUNT | Company | PREVIOUS COMPANY | ||||||
| 111 | 1/1/2023 | 1 | a | b | ||||||
| 222 | 1/1/2020 | 1 | c | a | ||||||
| 888 | 1/1/2022 | 1 | x | y | ||||||
| 222 | 1/1/2018 | 3 | b | |||||||
| 222 | 1/1/2019 | 2 | a | b | ||||||
| 111 | 1/1/2019 | 2 | b | |||||||
| 888 | 1/1/2020 | 2 | y |
I tried this but it didn't work:
Previous company = CALCULATE(
maxx ('Table', 'Table'[Company]),
filter ( 'Table', 'Table'[ID] = EARLIER('Table'[ID])
&& 'Table'[Running Count] >= EARLIER('Table'[Running Count] )))
Hi,
You do not need a running count column for that. Try this calculated column formula
Previous Company = LOOKUPVALUE(Data[Company],Data[date],CALCULATE(MAX(Data[date]),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[date]<EARLIER(Data[date]))),Data[ID],Data[ID])
Hope this helps.
You are welcome.
@Maha1 , a new measure
countx(filter(allselected(Table), Table[ID] = max(Table[ID]) && Table[Date] >= max(Table[Date]) ) , Table[ID])
You can also consider window function
Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
thank you
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 33 | |
| 25 | |
| 23 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 64 | |
| 41 | |
| 27 | |
| 22 | |
| 22 |