DAX / powerbi - grouped rowcount based on 2 columns and sorted by datetime

22 views Asked by At

I have a table with the following columns:

  • Different product with IDs: A, B, C...
  • Date and time of date recorded
  • State: can either be filled with string, or is empty

Which looks like this:

A - 01-01-2023 10:00 - Yes
A - 01-01-2023 11:00 - No
A - 01-01-2023 12:00 -
B - 01-01-2023 10:00 - Yes
B - 02-01-2023 10:00 -
B - 03-01-2023 10:00 -
C - 01-01-2023 15:00 - No
C - 01-01-2023 16:00 - Yes
C - 01-01-2023 17:00 - Yes

I have sorted the table to arrange the data in descending order of datetime, earliest to latest. I want to know, when the data is grouped by ID and sorted by date-time, when there are at least 2 empty cells for the "State" column. For example: after sorting the table, my products column will look like A,A,A,B,B,B,C,C,C,A,A,A,B,B,B,C,C,C. What I want is to group them By ID, and start a row count as soon as the "State" column is either filled or when it is Blank. The rowcount column would add the count like this:

A - 01-01-2023 10:00 - Yes - 1
A - 01-01-2023 11:00 - No  - 2
A - 01-01-2023 12:00 -     - 1
B - 01-01-2023 10:00 - Yes - 1
B - 02-01-2023 10:00 -     - 1
B - 03-01-2023 10:00 -     - 2
C - 01-01-2023 15:00 - No  - 1
C - 01-01-2023 16:00 - Yes - 2
C - 01-01-2023 17:00 - Yes - 3

I really want to solve this in DAX, because I want to learn more about this language.

I'm now trying something like this:

EmptyCellCount = RANKX(FILTER(Data,Data[ID]=EARLIER(Data[ID])),Data[date],,ASC,Dense)

or something like this:

EmptyCellCount = 
IF (
    ISBLANK ( Data[State] ),
    RANKX(FILTER(Data,Data[ID]=EARLIER(Blad1[ID])),Data[date],,ASC,Dense),
    BLANK ()
)
0

There are 0 answers