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
GrazieGracias
New Member

Apply measure only for a particular row

Hello,

 

I have a data set that summarizes the following items by Month and by Store.

  1. Sales
  2. Profit
  3. Operating Expenses
  4. Other Expenses
  5. Net Income (=Profit - Operating Expenses - Other Expenses)
  6. Margin (=Profit / Sales)

The aforementioned data set looks like below:

Capture2.JPG

(Name of the table: Table1)

 

My task is to create a table in PowerBI like below:

Capture.JPG

 

The problem I am trying to solve at the moment is to make Margin recalculated when multiple months are selected in the slicer (e.g., to show YTD amounts); As you can see below, Margin it sums up the margins for selected months instead of recalculating it, which I understand why.

Capture3.JPG

 

To make it recalculate Margin when multiple months are selected, I created the following measures, but it's not displaying anything for Margin.

AmountA:=CALCULATE(SUM(Table1[Amount]),Table1[Store]="A")

AmountAMargin:=CALCULATE([AMountA],Table1[Description]="Profit")/CALCULATE([AMountA],Table1[Description]="Sales")

AmountAFinal:=SUMX(Table1,SWITCH(TRUE(),Table1[Description]="Margin",[AmountAMargin],[AmountA]))

 

Capture4.JPG

 

Can you please advise?

 

Thanks much,

GrazieGracias

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@GrazieGracias ,

 

In general, this issue should be related to the the conditions in the measure haven't been met, so you may add ALL() function in your filter. Try modifying your code like dax below and check if the value is still blank. If this leads to other issue or incorrect value, please provide the expected result.

AmountA =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( ALL ( Table1 ), Table1[Store] = "A" )
)


AmountAMargin =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( ALL ( Table1 ), Table1[Description] = "Profit" && Table1[Store] = "A" )
)
    / CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER ( Table1, Table1[Description] = "Sales" && Table1[Store] = "A" )
    )


AmountAFinal =
SUMX (
    Table1,
    IF ( MAX ( Table1[Description] ) = "Margin", [AmountAMargin], [AmountA] )
)

Community Support Team _ Jimmy Tao

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

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@GrazieGracias ,

 

In general, this issue should be related to the the conditions in the measure haven't been met, so you may add ALL() function in your filter. Try modifying your code like dax below and check if the value is still blank. If this leads to other issue or incorrect value, please provide the expected result.

AmountA =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( ALL ( Table1 ), Table1[Store] = "A" )
)


AmountAMargin =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( ALL ( Table1 ), Table1[Description] = "Profit" && Table1[Store] = "A" )
)
    / CALCULATE (
        SUM ( Table1[Amount] ),
        FILTER ( Table1, Table1[Description] = "Sales" && Table1[Store] = "A" )
    )


AmountAFinal =
SUMX (
    Table1,
    IF ( MAX ( Table1[Description] ) = "Margin", [AmountAMargin], [AmountA] )
)

Community Support Team _ Jimmy Tao

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

Thanks for the help. I tweaked the codes a little bit and it works beautifully. The key ingredient was MAX, and I actually didn't have to use SUMX.

 

Thanks again!

GrazieGracias

 

Stachu
Community Champion
Community Champion

I'd try something like this:

AmountAFinal :=
IF (
    SELECTEDVALUE ( Table1[Description] ) = "Margin",
    [AmountAMargin],
    [AmountA]
)


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.