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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ptmuldoon
Resolver I
Resolver I

Measure Help to compute 'Total' based on prior month info

I'm struggle to get this measure figured out.

 

I have data that includes a "# of reponses" for a month, and then a total score for a particular item.  That looks like something like the below.

ptmuldoon_0-1736545788670.png

Now, in order for me to get the correct 3 month score, I need to multiple each months score by the reponse.  Then take that total divided by the total of the reponses.  And with some quick excel work, you can see the 3 month scores should be 71.1

ptmuldoon_1-1736545894598.png

 

I've been struggling with the Measure, and believe I need to use ISINSCOPE to correclty manipulate the total, but can't get this to work correctly yet.

Score = 
VAR TotalScore = Sum(SampleScores[Org Score]) * CALCULATE(Sum(SampleScores[Org Score]), SampleScores[Description] = "# of responses")

RETURN
    SWITCH(
        TRUE(),
        ISINSCOPE(SampleScores[Month]), Sum(SampleScores[Org Score]),
        DIVIDE(
            TotalScore,
            Calculate(Sum(SampleScores[Org Score]), SampleScores[Description] = "# of responses")
        )
    )

 

 

 

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @ptmuldoon 
The best practice for working with Power BI is to have separate columns for separate measures in the data table:

Ritaf1983_0-1736549967357.png

To achieve this you should pivot the columns in power query :

Ritaf1983_1-1736550108374.png

then you can create a date table + relationship with your "fact table"

Ritaf1983_2-1736550201631.pngRitaf1983_3-1736550224904.png

Then create a 3 measures :

Responses # = SUMX('Table','Table'[# of responses])
Scores =
AVERAGEX('Table','Table'[Intent to Recommend (Property)])
monthly score total = SUMX('Table',[Scores]*[Responses #])
Put all of them in the matrix with the modifying option "switch values at rows"
Ritaf1983_4-1736550376756.pngRitaf1983_5-1736550419695.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

6 REPLIES 6
danextian
Super User
Super User

Hi @ptmuldoon 

As what @Ritaf1983 has mentioned, it is a best practice to have a separate column for each measure because If your table isn't the proper shape, you'll end up with a lengthy DAX 😊

 

Score = 
VAR _responses =
    CALCULATE (
        SUM ( 'Table'[Org Score] ),
        KEEPFILTERS ( 'Table'[Description] = "# of responses" )
    )
VAR _intent =
    CALCULATE (
        SUM ( 'Table'[Org Score] ),
        KEEPFILTERS ( 'Table'[Description] = "Intent to Recommend (Property)" )
    )
VAR _total = _responses * _intent
VAR CellTotal =
    SUM ( 'Table'[Org Score] )
VAR IntentTotal =
    AVERAGEX ( VALUES ( 'Table'[Month] ), CALCULATE ( SUM ( 'Table'[Org Score] ) ) )
VAR GrandTotal =
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE ( 'Table', 'Table'[Month] ),
            "@total",
                CALCULATE (
                    SUM ( 'Table'[Org Score] ),
                    KEEPFILTERS ( 'Table'[Description] = "# of responses" )
                )
                    * CALCULATE (
                        SUM ( 'Table'[Org Score] ),
                        KEEPFILTERS ( 'Table'[Description] = "Intent to Recommend (Property)" )
                    )
        ),
        [@total]
    )
VAR result =
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( 'Table'[Description] ) = "Intent to Recommend (Property)", IntentTotal,
        SELECTEDVALUE ( 'Table'[Description] ) = "# of responses", CellTotal,
        GrandTotal
    )
RETURN
    result

 

danextian_0-1736664451241.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

@danextian 
Looks like we’re syncing thoughts in the forum lately 😊 It's Always great to see you around!🙃

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi @Ritaf1983

Thanks for noticing! 😁 It's always great to see you around too.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ritaf1983
Super User
Super User

Hi @ptmuldoon 
The best practice for working with Power BI is to have separate columns for separate measures in the data table:

Ritaf1983_0-1736549967357.png

To achieve this you should pivot the columns in power query :

Ritaf1983_1-1736550108374.png

then you can create a date table + relationship with your "fact table"

Ritaf1983_2-1736550201631.pngRitaf1983_3-1736550224904.png

Then create a 3 measures :

Responses # = SUMX('Table','Table'[# of responses])
Scores =
AVERAGEX('Table','Table'[Intent to Recommend (Property)])
monthly score total = SUMX('Table',[Scores]*[Responses #])
Put all of them in the matrix with the modifying option "switch values at rows"
Ritaf1983_4-1736550376756.pngRitaf1983_5-1736550419695.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thanks.

 

I ended up modifying the import to add some additional column to compute the 'raw score' there, and then simplified the measure.  Not sure why I didn't think of that earlier.

 

And I'll be adding this into a larger dataset that already had the Date Table set up, etc.   

hnguy71
Super User
Super User

Hi @ptmuldoon ,
Try this. Of course, replace any incorrect fields with your fields:

Score = 

VAR _Description = SELECTEDVALUE(SampleScores[Description])

// Generate results, one for each description
VAR _SummarizeMe = 
SUMMARIZE(SampleScores, [Month], 
    "@Responses", CALCULATE(SUM(SampleScores[Org Score]), KEEPFILTERS(SampleScores[Description] = "# OF RESPONSES")),
    "@Scores", CALCULATE(SUM(SampleScores[Org Score]), KEEPFILTERS(SampleScores[Description] = "SCORES"))
)


RETURN

// check to see if current row context matches string
SWITCH( _Description,
    "# OF RESPONSES", SUMX(_SummarizeMe, [@Responses]),
    "SCORES", SUMX(_SummarizeMe, [@Scores]),

    // if not, must be the row total line, let's multiple everything
    SUMX(_SummarizeMe, [@Responses] * [@Scores])
)

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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