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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Stuznet
Helper V
Helper V

Sum specific Rows Then Divide Sum of One Column by Sum of Another Column

I'm struggling with a simple Sum and divide. How do I write a Total% measure and turn this Excel formula to DAX?

 2018-10-05_20-53-28.png

 

I've tried this function but I'm not getting the correct result

Col1 = CALCULATE([Col1_Total],ALL(MonthTable[Month]),OR(MonthTable[Month] = "April", MonthTable[Month] = "May"))
Col2 = CALCULATE([Col1_Total],ALL(MonthTable[Month]),OR(MonthTable[Month] = "April", MonthTable[Month] = "May"))
Total = [Col1_Total] / [Col2_Total]

 2018-10-05_21-22-09.png


Thank you 

1 ACCEPTED SOLUTION

@Ashish_Mathur@v-lili6-msftthank you so much for your help 🙂 , unfortunately I could not utilize the functions you provided. I ended up with the Variables statement instead and much tideous. 

 

Measure 4 = 
VAR Col1_Apr = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1, Table1 [Data]="March"),FILTER(Table1, Table1 [S Month]="April"),FILTER(Table1, Table1 [S Year]="2018"))
VAR Col1_May = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="April"),FILTER(Table1,Table1[S Month]="May"),FILTER(Table1,Table1[S Year]="2018"))
VAR Col2_Apr = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="May"),FILTER(Table1,Table1[S Month]="April"),FILTER(Table1,Table1[S Year]="2018"))
VAR Col2_May  = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="June"),FILTER(Table1,Table1[S Month]="May"),FILTER(Table1,Table1[S Year]="2018"))

RETURN
(Col2_Apr + Col2_May  ) / (Col1_Apr + Col1_May)

Total Start% = SWITCH(TRUE(),

MAX(MonthTable[Month]) = "April",
    CALCULATE([Measure4]),

MAX(MonthTable[Month]) = "May",
    CALCULATE([Measure5]),
    
MAX(MonthTable[Month]) = "June",
    CALCULATE([Measure6]))

 2018-10-08_9-56-51.png

View solution in original post

8 REPLIES 8
v-lili6-msft
Community Support
Community Support

HI, @Stuznet

     You may try to use TOTALYTD Function or DATESYTD Function in your measure as below

 

Measure = TOTALYTD(SUM(Table1[Col2]),'Date'[Date])/TOTALYTD(SUM(Table1[Col1]),'Date'[Date])

Result:

 

1.PNG

 

By the way,  

DATESYTD ( 'Date'[Date] )

It corresponds to a filter over the date column using FILTER called by CALCULATETABLE, such as in the following code:

CALCULATETABLE (
    FILTER (
        ALL ( 'Date'[Date] ),
        AND (
            'Date'[Date] <= MAX ( 'Date'[Date] ),
            YEAR ( 'Date'[Date] ) = YEAR ( MAX ( 'Date'[Date] ) )
        )
    )
)

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.

@Ashish_Mathur@v-lili6-msftthank you so much for your help 🙂 , unfortunately I could not utilize the functions you provided. I ended up with the Variables statement instead and much tideous. 

 

Measure 4 = 
VAR Col1_Apr = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1, Table1 [Data]="March"),FILTER(Table1, Table1 [S Month]="April"),FILTER(Table1, Table1 [S Year]="2018"))
VAR Col1_May = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="April"),FILTER(Table1,Table1[S Month]="May"),FILTER(Table1,Table1[S Year]="2018"))
VAR Col2_Apr = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="May"),FILTER(Table1,Table1[S Month]="April"),FILTER(Table1,Table1[S Year]="2018"))
VAR Col2_May  = CALCULATE(COUNTA(Table1[ID]),FILTER(Table1,Table1[Data]="June"),FILTER(Table1,Table1[S Month]="May"),FILTER(Table1,Table1[S Year]="2018"))

RETURN
(Col2_Apr + Col2_May  ) / (Col1_Apr + Col1_May)

Total Start% = SWITCH(TRUE(),

MAX(MonthTable[Month]) = "April",
    CALCULATE([Measure4]),

MAX(MonthTable[Month]) = "May",
    CALCULATE([Measure5]),
    
MAX(MonthTable[Month]) = "June",
    CALCULATE([Measure6]))

 2018-10-08_9-56-51.png

Ashish_Mathur
Super User
Super User

Hi,
 
What do Col1 and Col2 represent?  Are years?  If yes, then which years?  If not, then for which year is this data?

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur Col1 and Col2 represent count of IDs

I understand that.  But that has to for year(s), Cities(s), Stores(s).  Please clarify.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathursorry, lets use count of Cities

Hi,

 

You may refer to my solution in this PBI file.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_MathurThank you for sharing your solution but it is almost close enough what I'm looking for. I just don't know how to rewrite your function. 

 

So here is my function.

Month Table just like your Month_Order table

January to December

 

Measure Col1

Col1 = SWITCH(TRUE(),

MAX(Table2[Month]) = "April",CALCULATE(
            COUNT(Table1[ID]),FILTER(DATA,[Start Month]="April"
                && [Start Year] = "2018"
                && [Data] = "March")),

MAX(Table2[Month]) = "May", CALCULATE(
            COUNT(Table1[ID]),FILTER(Table1,[Start Month]="May"
                && [Start Year] = "2018"
                && [Data] = "April")),

MAX ( Table2[month] ) = "June", CALCULATE (
            COUNT(Table1[ID]),FILTER (Table1,[Start Month]= "June"
                && [Start Year] = "2018"
                && [Data] = "May")))

Measure Col2

Col2 = SWITCH(TRUE(),

MAX(Table2[Month]) = "April",CALCULATE(
            COUNT(Table1[ID]),FILTER(Table1,[Finish Month]="April"
                && [Finish Year] = "2018"
                && [Data] = "May")),

MAX(Table2[Month]) = "May",CALCULATE(
            COUNT(Table1[ID]),FILTER(Table1,[Finish Month]="May"
                && [Finish Year] = "2018"
                && [Data] = "June")),

MAX(Table2[Month]) = "June",CALCULATE(
            COUNT(Table1[ID]),FILTER(Table1,[Finish Month]="June"
                && [Finish Year] = "2018"
                && [Data] = "July")))

Measure Total% 

Total % = [Col1Total] / [Col2Total]

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.