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
Anonymous
Not applicable

calculation from specific rows and columns

Dear team, 

Please help me with this problem scenario

 

Parameter                  Target          Actual 

 

A                                   15               12

B                                   18               14

C                                   10               11

D                                   15               16

 

Please note that this is a dummy data, the actual data set may have 100+ such rows

 

Formula = (Sum of B and C Target Value)/( Sum of A and D actual value),

 = ( 18+10)/(12+16) = 1

 

Note: the formula output has to be displayed on a card.

 

Thanks!

2 ACCEPTED SOLUTIONS
edhans
Super User
Super User

This will work, returning 1 in a card.

Measure = 
VAR varNumerator = 
SUMX(
    FILTER(
        'Table',
        'Table'[Parameter ] = "B" || 'Table'[Parameter ] = "C"
    ),
    'Table'[Target         ]
)
VAR varDenomenator = 
SUMX(
    FILTER(
        'Table',
        'Table'[Parameter ] = "A" || 'Table'[Parameter ] = "D"
    ),
    'Table'[Actual ]
)
VAR Result = 
    DIVIDE(
        varNumerator,
        varDenomenator,
        0
    )
RETURN
    Result

 

Note: The field names have a bunch of spaces. I didn't realize that until I was well into doing the measure and wasn't going to go back and fix the source data. If you need further help, please see the links below for supplying data.

If this works for you, please mark it the solution.
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could unpivot the "Target" and "Actual" columns in the query editor.

1-1.PNG

Then use filter to get the result.

Measure =
VAR a =
    SUMX (
        FILTER (
            'Table',
            'Table'[Parameter] IN { "B", "C" }
                && 'Table'[Attribute] = "Target"
        ),
        'Table'[Value]
    )
VAR b =
    SUMX (
        FILTER (
            'Table',
            'Table'[Parameter] IN { "A", "D" }
                && 'Table'[Attribute] = "Actual"
        ),
        'Table'[Value]
    )
RETURN
    DIVIDE ( a, b )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

3 REPLIES 3
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could unpivot the "Target" and "Actual" columns in the query editor.

1-1.PNG

Then use filter to get the result.

Measure =
VAR a =
    SUMX (
        FILTER (
            'Table',
            'Table'[Parameter] IN { "B", "C" }
                && 'Table'[Attribute] = "Target"
        ),
        'Table'[Value]
    )
VAR b =
    SUMX (
        FILTER (
            'Table',
            'Table'[Parameter] IN { "A", "D" }
                && 'Table'[Attribute] = "Actual"
        ),
        'Table'[Value]
    )
RETURN
    DIVIDE ( a, b )

Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Ashish_Mathur
Super User
Super User

Hi,

This measure works

Measure = CALCULATE(SUM(Data[Target]),Data[Parameter]="B"||Data[Parameter]="C")/CALCULATE(SUM(Data[Target]),Data[Parameter]="A"||Data[Parameter]="D")

Hope this helps.

Untitled.png


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

This will work, returning 1 in a card.

Measure = 
VAR varNumerator = 
SUMX(
    FILTER(
        'Table',
        'Table'[Parameter ] = "B" || 'Table'[Parameter ] = "C"
    ),
    'Table'[Target         ]
)
VAR varDenomenator = 
SUMX(
    FILTER(
        'Table',
        'Table'[Parameter ] = "A" || 'Table'[Parameter ] = "D"
    ),
    'Table'[Actual ]
)
VAR Result = 
    DIVIDE(
        varNumerator,
        varDenomenator,
        0
    )
RETURN
    Result

 

Note: The field names have a bunch of spaces. I didn't realize that until I was well into doing the measure and wasn't going to go back and fix the source data. If you need further help, please see the links below for supplying data.

If this works for you, please mark it the solution.
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.