cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SimonChung_GGGG
Helper III
Helper III

Count control by Date Slicer

Hi Experts, 

 

Please find the PBIX Download Here 

There is a measure to calculate "Count", "Units", "Sales", "Margin", the values will be changed by the Date slicer 

Value by Class = 

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class]= SELECTEDVALUE('Pareto classification'[Product class]))

RETURN 
 SWITCH (SELECTEDVALUE('P&L'[P&L]),
 "Count", COUNTROWS(currentClassTable)
 , "Units" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Units])))
 , "Sales" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Sales])))
, "Margin", SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Margin]))))

For example below, the Circled Bottom Products is expected to 3, but I cannot do that, would anyone help, many thanks

image.png

 

 

 

1 ACCEPTED SOLUTION

@SimonChung_GGGG , count calculation is wrong

Try

Value by Class = 

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in values('Pareto classification'[Product class]))

RETURN 
 SWITCH (SELECTEDVALUE('P&L'[P&L]),
 "Count",  SUMX(currentClassTable, CALCULATE(DISTINCTCOUNT('Sales table'[Product])))// COUNTROWS(currentClassTable)
 , "Units" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Units])))
 , "Sales" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Sales])))
, "Margin", SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Margin]))))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@SimonChung_GGGG , Try these

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in values('Pareto classification'[Product class]))

or

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in allselected('Pareto classification'[Product class]))

 

but if they are related table you do not need to do this

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

@amitchandak Thanks so much! However it doesn't work, the results are as below. 

 

 

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in values('Pareto classification'[Product class]))

image.png

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in allselected('Pareto classification'[Product class]))

image.png

@SimonChung_GGGG , count calculation is wrong

Try

Value by Class = 

VAR currentClassTable = FILTER(ALLSELECTED('Sales table'[Product]), [Class] in values('Pareto classification'[Product class]))

RETURN 
 SWITCH (SELECTEDVALUE('P&L'[P&L]),
 "Count",  SUMX(currentClassTable, CALCULATE(DISTINCTCOUNT('Sales table'[Product])))// COUNTROWS(currentClassTable)
 , "Units" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Units])))
 , "Sales" , SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Sales])))
, "Margin", SUMX(currentClassTable, CALCULATE(SUM('Sales table'[Margin]))))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

@amitchandak  It's work now, many thanks

Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it Out!

Join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!