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

Measure to count distinct number of ids where two other measure are not equal

I have a history table with that pulls a view of a database at the beginning of every month and assigns a date to the rows associated with that pull (I made a brief summary below, there are many more fields in the table)

 

productId                Status                         ViewDate

      1                         active                          5/1/2019

      1                         active                          6/1/2019

      1                         inactive                       7/1/2019

      2                         active                          5/1/2019

      2                         hold                            6/1/2019

      2                         hold                            7/1/2019

 

I have two slicers linked to disconnected tables that each contain distinct values from the viewdate field (ViewDateStart and ViewDateEnd)

 

And the following two measures to pull the starting status and the ending status for each product based on user selection:

statusStart = CALCULATE(MAX(table[status],

                             FILTER(table, table[ViewDate]=SELECTEDVALUE(ViewDateStart[ViewDate])

 

statusEnd = CALCULATE(MAX(table[status],

                             FILTER(table, table[ViewDate]=SELECTEDVALUE(ViewDateEnd[ViewDate])

 

When I place the measures above in a table with the products as the dimension I get the correct starting and ending status for each product based on slicer selections

 

I need to create a measure that calculates the number of distinct products where statusStart <> statusEnd

 

I have tried the following but I think I am missing a grouping step as this is flagging every product ID not just those with status changes based on slicer selections

 

StatusChangeCount = CALCULATE(DISTINCTCOUNT(table[productId]), FILTER(table, [statusStart] <> [statusEnd]))

 

Is there a way to do this in Power BI?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Measure to count distinct number of ids where two other measure are not equal

hi, @saschatt 

You may try this way:

Add a measure like this:

measure = IF([statusStart]<>[statusEnd],1,0)

Then SUM this measure value by group.

Combine these two steps by this formula

changecounta = SUMX(SUMMARIZE('table','table'[productId]) , IF([statusStart]<>[statusEnd],1,0) )

 

If you have problem for the measure total, please refer to these two posts:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

And if not your problem, please share your sample pbix file and 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.

View solution in original post

1 REPLY 1
Community Support Team
Community Support Team

Re: Measure to count distinct number of ids where two other measure are not equal

hi, @saschatt 

You may try this way:

Add a measure like this:

measure = IF([statusStart]<>[statusEnd],1,0)

Then SUM this measure value by group.

Combine these two steps by this formula

changecounta = SUMX(SUMMARIZE('table','table'[productId]) , IF([statusStart]<>[statusEnd],1,0) )

 

If you have problem for the measure total, please refer to these two posts:

https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

And if not your problem, please share your sample pbix file and 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.

View solution in original post

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors