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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sicaniaa90
New Member

Count latest status per id per date in stacked bar chart

Dear fellow PBI enthusiasts!

 

As a beginner, I have reached the limit of my knowledge within PBI, and I really hope that some of you will help me out with this issue.

Goal

In a stacked bar chart I want to evaluate for every date what is the count of the latest status of all active cases.

Illustration of end result:

sicaniaa90_0-1673896744871.png

 

Tables overview:

Case Table:

sicaniaa90_1-1673896993031.png

Date Table:

sicaniaa90_2-1673897200105.png

 

Relationships:

My 'Date Table' and 'Case Table' have a one-to-many relationsship. I reckon that I will have to iterate over each date in the date table and execute a calculation.

 

Progress so far

I have managed to make a measure that evaluates for every row in 'Case Table' if the date of the status-change is the latest

The code:

Last_date =
VAR MaxDate =
    CALCULATE(
        MAX('Case Table'[Date])
    )

VAR CALC = CALCULATE(
    MAX('Case Table'[Status]),
    FILTER(
        'Case Table',
        'Case Table'[Date] = MaxDate
    ),
    USERELATIONSHIP('Case Table'[Date],'Date Table'[Date])
)
 
RETURN
IF(CALC <> "Done", CALC)

 

When I use this measure in a table in combination with a date-slicer im a able to retrieve the correct list of the latest status of an active case, and at the same time exclude cases that has the status "Done".

 

sicaniaa90_3-1673897453801.png

 

I would highly appreciate any help that can bring me closer to a solution.

Download PBIX-file:

In case you want to download the file I am working in.

https://drive.google.com/file/d/17-0TKpOI52mzexXoGkYoy_TFydZQ_bh2/view?usp=sharing

 

Best regards

Simon

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

14 REPLIES 14
sicaniaa90
New Member

Dear @amitchandak 

Thank you for pointing me in the right direction!

I seems that your code could be tweaked to solve the problem. However, I would need to make a calculated column in my 'Date Table' that executes [Sum Last Qty] for every date and only sum on the rows in the 'Case Table' that are below or equal to the current date selected:

Last Qty = Var _max = maxx(filter( ALLSELECTED(Data1), Data1[ID] = max(Data1[ID]) ),Data1[Date])
return 
CALCULATE(sum(Data1[qty]), filter( (Data1), Data1[ID] = max(Data1[ID])  && Data1[Date] =_max))

Sum Last Qty = sumx(VALUES(Data1[ID]) , [Last Qty])

Do you have any ideas as to how i could do that? 

Best regards

Simon

sicaniaa90
New Member

Dear @Ashish_Mathur  

Thank you for your reply!

 

If this is the input 'Case Table':

IDStatusDate
ID2Created02/01/2022
ID1Created02/01/2022
ID1Wait07/01/2022
ID3Created07/01/2022
ID2In Progress10/01/2022
ID1In Progress13/01/2022
ID3Done14/01/2022
ID1Done20/01/2022

 

The following 'Date Table' would solve my problem:

Date Status (Created)Status (Wait)Status (In Progress)
01/01/2022 000
02/01/2022 200
03/01/2022 200
04/01/2022 200
05/01/2022 200
06/01/2022 200
07/01/2022 210
08/01/2022 210
09/01/2022 210
10/01/2022 111
Etc.    

 

In this table, it should evaluate for every date, what is the latest date of each ID in the 'Case Table', that is below or equal to the selected date in the 'Date Table'.

 

In each column, the calculation should count only the ID's with this specific status. The visual in the end should look like this:

 

sicaniaa90_0-1673937593696.png

 

@Ashish_Mathur : Do you have an idea how to accomplish this?

 

Best regards

Simon

 

Hi Simon, I'm stuck on exactly the same problem. Could you please paste the solution here? (the data file is no longer available....) Much much appreicated!!!!!!

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi, Could you please the formula you used to get this end result? THank you so much!!

Hi,

I do not have the file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This was the original file from the first original post: https://drive.google.com/file/d/17-0TKpOI52mzexXoGkYoy_TFydZQ_bh2/view?usp=sharing

 

Would you be so nice to replicate the solution again? I am so stuck.....

 

Thank you in advance.

Without referring to the question asked previoussly, please explain your question and show the exact result that you are expecting.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello, can you share this file again? I have same problem i now try to find answers. 

I need count status on current date (choosen) in pivot table (power bi).

I will be grateful.  

Hi,

I do not have the file.  Please share some data, explain the question and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you so much Ashish, your solution worked wonders for me!

Best

Simon

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

In a simple Table, please show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.