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
Sperling
Helper II
Helper II

Divide count by sum of the same column

Hi,

 

I have a dataset similar to the information below, with customers paying different prices based on a chosen time slot in a calendar.

 PriceAmount of customers
 50200
 75100
 10050
Total 350

 

Currently I use this measure to find the amount of customers:

 

Amount of customers =

CALCULATE(
COUNTROWS(QUERY),
QUERY[Calendar] = "/calendar"
)

I want to calculate the share of customers choosing each of the options.

I thought it was a simple task, but I can't seem to find out how to divide "Amount of customers" by the sum of "Amount of customers".

 

1 ACCEPTED SOLUTION

Hi @Sperling 

Try this, create the measures below,

SumEachPrice = 
    CALCULATE (
        SUM ( FactTable[Customer] ),
        FILTER (
            ALL ( FactTable ),
            FactTable[Price] = MIN ( FactTable[Price] )
                && FactTable[Date] >= MINX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
                && FactTable[Date] <= MAXX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
        )
    )
Sum of Amount_of_customers = 
    CALCULATE (
        SUM ( FactTable[Customer] ),
        FILTER (
            ALL ( FactTable ),
            FactTable[Date] >= MINX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
                && FactTable[Date] <= MAXX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
        )
    )
Amount of customers = 
    IF ( HASONEVALUE ( PriceTable[Price] ), [SumEachPrice], [Sum of Amount_of_customers] )
Divide = DIVIDE([Amount of customers],[Sum of Amount_of_customers])

result

vxiaotang_0-1651652836033.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Thejeswar
Resident Rockstar
Resident Rockstar

HI @Sperling ,

You can get the % of customer using the below DAX formula

%ofCustomer = 
VAR currentamountofcustomers  = [Amount of customers]
VAR Totalcustomers = CALCULATE([Amount of customers], REMOVEFILTERS('Table2'))
RETURN
DIVIDE(currentamountofcustomers, Totalcustomers)

 

Mark the measure as a %

Below is the reference SS

Thejeswar_0-1649858198992.png

 

Regards,

 

Thanks for the quick reply!


The solution works when I have my other measures unfiltered.
However I'm looking at multiple sites, and when I filter the page to look at a specific site, it still uses the same total as the one from the variable you created below:

VAR Totalcustomers = CALCULATE([Amount of customers], REMOVEFILTERS('Table2'))

 

Any idea how to approach getting around this filtering issue?

Hi @Sperling 

Try this, create the measures below,

SumEachPrice = 
    CALCULATE (
        SUM ( FactTable[Customer] ),
        FILTER (
            ALL ( FactTable ),
            FactTable[Price] = MIN ( FactTable[Price] )
                && FactTable[Date] >= MINX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
                && FactTable[Date] <= MAXX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
        )
    )
Sum of Amount_of_customers = 
    CALCULATE (
        SUM ( FactTable[Customer] ),
        FILTER (
            ALL ( FactTable ),
            FactTable[Date] >= MINX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
                && FactTable[Date] <= MAXX ( ALLSELECTED ( 'Calendar' ), Calendar[Date] )
        )
    )
Amount of customers = 
    IF ( HASONEVALUE ( PriceTable[Price] ), [SumEachPrice], [Sum of Amount_of_customers] )
Divide = DIVIDE([Amount of customers],[Sum of Amount_of_customers])

result

vxiaotang_0-1651652836033.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors