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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
RandomWalker
Frequent Visitor

Fill in a measure value to all rows in a new measure by group

Hi Members,

I'm working on a dashboard where I need to compute the ratio between two measures. To be more specific, I'd like to

get the ratio between Average Amount and Ref, both are measures, as shown in the screenshot. For each FY, the Ref

value is the one in the WI category (indicated by arrows). I managed to get the WI category value show up

in the Ref measure, but I am having difficulties to populate the value by FY group. My case is a bit complicated because

I need to use slicers on FY/Size/Category to showcase the ratio in various scenarios. In the screenshot, Total Amount,

Total Order, Average Amount are all measures.

 

I did a little bit of search and came across three cases that are very close to my situation:

However none of the solutions work in my case. It'd be appreciated if experts here could help me find a solutuon.

Thank you for your time!

-------------------------------------------

Sample PBIX file: filter_test.pbix

Sample data: Sample.csv

 

expected_result.png

1 ACCEPTED SOLUTION
RandomWalker
Frequent Visitor

Note: the following is not strictly a DAX solution, it's just a workaround based on data model change. 

 

After some thougts, I decided to change the data model by adding two more columns for WI category Order and Amount data in each group. (You could find the original data in the link above)

 

Screenshot 2024-01-17 at 11.37.11 PM.png

 

With this structure, it becomes straightforward to just compute Total Amount, Total Order, and Ave Amount measures using these DAX expressions:

 

 

Tot Amount = 
    SUMX(
        KEEPFILTERS(VALUES(Sample[Amount])),
        CALCULATE(
            SUM(Sample[Amount])
        )
    )

Tot Order = 
    SUMX(KEEPFILTERS(VALUES(Sample[Order])), CALCULATE(SUM(Sample[Order])))


Avg Amount = 
VAR _amt = 
    SUMX( KEEPFILTERS(VALUES(Sample[Amount])), CALCULATE(SUM(Sample[Amount])) )
VAR _order = 
    SUMX( KEEPFILTERS(VALUES(Sample[Order])), CALCULATE(SUM(Sample[Order])) )
RETURN
    DIVIDE( _amt, _order)

 

 

 

Then I just create the same measure (with the WI category data) for the added wOrder and wAmount columns in the new data model.

 

Screenshot 2024-01-17 at 11.44.20 PM.png

With this data structure modification, the calculation of ratio becomes trivial and the results plays very well with slicers:

Screenshot 2024-01-17 at 11.38.27 PM.png

View solution in original post

3 REPLIES 3
RandomWalker
Frequent Visitor

Note: the following is not strictly a DAX solution, it's just a workaround based on data model change. 

 

After some thougts, I decided to change the data model by adding two more columns for WI category Order and Amount data in each group. (You could find the original data in the link above)

 

Screenshot 2024-01-17 at 11.37.11 PM.png

 

With this structure, it becomes straightforward to just compute Total Amount, Total Order, and Ave Amount measures using these DAX expressions:

 

 

Tot Amount = 
    SUMX(
        KEEPFILTERS(VALUES(Sample[Amount])),
        CALCULATE(
            SUM(Sample[Amount])
        )
    )

Tot Order = 
    SUMX(KEEPFILTERS(VALUES(Sample[Order])), CALCULATE(SUM(Sample[Order])))


Avg Amount = 
VAR _amt = 
    SUMX( KEEPFILTERS(VALUES(Sample[Amount])), CALCULATE(SUM(Sample[Amount])) )
VAR _order = 
    SUMX( KEEPFILTERS(VALUES(Sample[Order])), CALCULATE(SUM(Sample[Order])) )
RETURN
    DIVIDE( _amt, _order)

 

 

 

Then I just create the same measure (with the WI category data) for the added wOrder and wAmount columns in the new data model.

 

Screenshot 2024-01-17 at 11.44.20 PM.png

With this data structure modification, the calculation of ratio becomes trivial and the results plays very well with slicers:

Screenshot 2024-01-17 at 11.38.27 PM.png

Hi @RandomWalker 

Thanks for sharing!

Best Regards,

Jayleny

 

 

RandomWalker
Frequent Visitor

I think I'm getting there but not quite yet. Inspired by this post, it seems that with this Ref measure:

 

Ref = 
    CALCULATE(
        [Avg Amount],
        FILTER(
            ALLSELECTED(Sample),
            Sample[Category] = "WI"
        ),
        VALUES(Sample[FY])
    )

 

 

I am able to propagate the value of category WI to the rows by FY:

 

result01.png 

 

 

 

 

 

 

 

However, this measure does not play well with the Category slicer. For example, if OT is selected in the silcer, Ref column is empty and the ratio is not correct:

 

result02.png

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

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.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.