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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
av9
Helper III
Helper III

Subtract a Count measure from MIN per category measure

Hi

I am trying to calculate a measure whereby I am subtracting one measure from another.

Sample of Marketing table data:

ContactIDEventCategory
1clickWebsite
1clickNewsletter
2clickWebsite
3clickArticle
3clickWebsite
3clickNewsletter
4clickNewsletter
5clickWebsite

 

The first measure is a count of clicks:

Click Count = CALCULATE (
COUNT ( 'Marketing'[Contactid] ),
FILTER (
'Marketing',
'Marketing'[Event] = "click"
))

The second measure calculates the minimum click count per category.

Min Click Count = VAR ValuesDisplayed =
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE ( Marketing, Marketing[Category] ),
"@Click", [Click Count]
),
ALLSELECTED(Marketing[Category])
)
RETURN
MINX ( ValuesDisplayed, [@Click])

I have another measure which subtracts these but I then find the totals when I view it in a table are not totalling correctly.

 

Adjusted Click Count = [Click Count]-[Min Click Count]

 

A sample of the final output looks like this table. The totals in the Adjusted click count is not right. Shows as 7 instead of 5.

CategoryClick CountMin Click CountAdjusted Click Count
Website413
Newsletter312
Article110
Total817

 

Is there another way I can approach this to get the right totals?

 

4 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@av9 , Try measure like

 

Adjusted Click Count = sumx(values(Marketing[Category]), [Click Count]-[Min Click Count])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Thanks I tried this measure and it gives me the correct total 5 but for each row per category its zero. is there a measure tha can do both?

 

CategoryClick CountMin Click CountAdjusted Click Count
Website410
Newsletter310
Article110
Total815

View solution in original post

@av9 , make sure category is coming from Marketing table in visual

 

 

if still did not work try like 

 

Adjusted Click Count =

 

if( isinscope(Marketing[Category]) , [Click Count]-[Min Click Count] ,

sumx(values(Marketing[Category]), [Click Count]-[Min Click Count])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

CNENFRNL
Community Champion
Community Champion

Rewrite the measures in a more concise and logical way,

 

 

Click Count = COUNTROWS( Marketing )

Min Click Count = MINX( ALL( Marketing[Category] ), [Click Count] )

Adjusted Click Count = 
SUMX ( DISTINCT ( Marketing[Category] ), [Click Count] - [Min Click Count] )

 

 

Screenshot 2021-07-14 114724.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

5 REPLIES 5
CNENFRNL
Community Champion
Community Champion

Rewrite the measures in a more concise and logical way,

 

 

Click Count = COUNTROWS( Marketing )

Min Click Count = MINX( ALL( Marketing[Category] ), [Click Count] )

Adjusted Click Count = 
SUMX ( DISTINCT ( Marketing[Category] ), [Click Count] - [Min Click Count] )

 

 

Screenshot 2021-07-14 114724.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@av9 , Try measure like

 

Adjusted Click Count = sumx(values(Marketing[Category]), [Click Count]-[Min Click Count])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks I tried this measure and it gives me the correct total 5 but for each row per category its zero. is there a measure tha can do both?

 

CategoryClick CountMin Click CountAdjusted Click Count
Website410
Newsletter310
Article110
Total815

@av9 , make sure category is coming from Marketing table in visual

 

 

if still did not work try like 

 

Adjusted Click Count =

 

if( isinscope(Marketing[Category]) , [Click Count]-[Min Click Count] ,

sumx(values(Marketing[Category]), [Click Count]-[Min Click Count])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for clarification

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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