cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AKSteffensen
Frequent Visitor

DAX COUNTROWS - Count only last date occurence

Hi,

 

I have data on the following form:

 

Case keyStart DateCase TypeCase Status
A-111-05-2019AOpen
A-112-05-2019AIn progress
A-112-05-2019ARefining
A-113-05-2019AClosed
B-211-05-2019BOpen
B-211-05-2019BIn progress
B-212-05-2019BDeveloped
B-213-05-2019BRefining
B-213-05-2019BClosed

 

I would like to create a DAX measure, that counts the amount of cases, which i can then split in graphs using different legens etc. However, when a case has multiple statusses in a single date, i only want the DAX measure to consider the last row, i.e. status "Refining" for case A-1 on 12-05-2019, "In progress" for case B-2 on 11-05-2019 and "Closed" for case B-2 on 13-05-2019. 

 

I am currently counting the rows using

 

Row Count = COUNTROWS( DISTINCT ( 'IssueHistory_FilledDates' ) )

Is there a neat way to make COUNTROWS only consider the last row, when there are multiple observations for a case on the same date?

 

Thank you in advance!

Best regards,

Andreas

 

1 ACCEPTED SOLUTION

hi, @AKSteffensen 

The logic of measure is that, And what you want is add a conditional to filter case stats column that is not the last observation.

Otherwise, how to filter case status in the visual

10.JPG

So just try add these steps:

Step1:

In Edit Queries, add an index column (to determine which case status is the last for the same date)

Step2:

Add a calculate column that if the row case status is last case status

tag = IF(CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Case key]=EARLIER('Table'[Case key])&&'Table'[Start Date]=EARLIER('Table'[Start Date])))='Table'[Index],'Table'[Case Status])

Step3:

Use Measure and other fileds to create a visual and this column to filter the data is not blank

Result:

11.JPG12.JPG

here is pbix file, please try it

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi, @AKSteffensen 

You could add the two measure

last occurence = CALCULATE(MAX('Table'[Case Status]),FILTER(ALLSELECTED('Table'),'Table'[Case key]=MAX('Table'[Case key])&&'Table'[Start Date]=MAX('Table'[Start Date])))
Count result = 
 CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Case Status]=[last occurence]))

If not your case, please share the expected output.

 

Best Regards,

Lin

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lili6-msft ,

 

Thank you for the answer. Unfortunately, it does not seem to work for what I need. Say i have the table outlined above. I then basically need a measure that counts the amount of rows. However, only the last observation should be counted if a case key has two observations with the same start date. Say i want to visualize the count measure based on 'Start Date' and 'Case Status'. The desired output would then be: 

 

 

Start DateCase StatusCount
11-05-2019Open1
11-05-2019In progress1
12-05-2019Refining1
12-05-2019Developed1
13-05-2019Closed2

 

Obviously, the counts could be a lot higher, since there are many more cases in the actual data set.

 

Thank you for your time.

 

 

hi, @AKSteffensen 

The logic of measure is that, And what you want is add a conditional to filter case stats column that is not the last observation.

Otherwise, how to filter case status in the visual

10.JPG

So just try add these steps:

Step1:

In Edit Queries, add an index column (to determine which case status is the last for the same date)

Step2:

Add a calculate column that if the row case status is last case status

tag = IF(CALCULATE(MAX('Table'[Index]),FILTER('Table','Table'[Case key]=EARLIER('Table'[Case key])&&'Table'[Start Date]=EARLIER('Table'[Start Date])))='Table'[Index],'Table'[Case Status])

Step3:

Use Measure and other fileds to create a visual and this column to filter the data is not blank

Result:

11.JPG12.JPG

here is pbix file, please try it

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-lili6-msft - Thank you so much for the very fast reply.

 

I will give it a go and see if I can make it work!

 

UPDATE: Works like a charm, thank you!

 

Best regards,

Andreas

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors