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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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