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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Community Champion
Community Champion

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.