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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
theitguy
Helper I
Helper I

Group By Won't Work - How to aggregate?

Hi guys,

 

What I have:

Learning Sessions:

Participant_IDUnique_Test_IDSingle_Session_IDLaunch_DateSeconds_SpendStatusScore
1t_012098417-11-2017444incomplete0
1t_012327117-11-201724incomplete0
1t_012327217-11-2017123complete12
1t_022327319-11-2017974complete36
4t_032097023-11-2017439incomplete0
4t_042330123-11-20171complete66
5t_052093505-11-201784incomplete0
5t_062181905-11-201728incomplete0
5t_052181717-11-201772incomplete0
5t_062098317-11-2017373complete80

 

Participants:

Participant_IDNameDepartmentCodeHire_Date
1John Doe1234501-11-2017
2Max Mustermann1234501-11-2017
3John Smith1234501-11-2017
4Jan Janssen1234501-11-2017
5John Blow12345601-11-2017

 

Want I want:

  • Measure1: For each test of a participant, I want the sum of [Seconds_Spend], e.g. for participant "1" and test with id "t_01" I want "591"
  • Measure2: For each test of a participant, I want the last entry of [Score], e.g. for participant "1" and test with id "t_01" I want to get "12"

Unfortunately, I cannot use GroupBy because multiple columns cannot be converted to a scalar value. Do I have to change my database design to achieve what I want?

6 REPLIES 6
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @theitguy,

 


  • Measure1: For each test of a participant, I want the sum of [Seconds_Spend], e.g. for participant "1" and test with id "t_01" I want "591"
  • Measure2: For each test of a participant, I want the last entry of [Score], e.g. for participant "1" and test with id "t_01" I want to get "12" 

I am not sure how to determine the "last entry of [Score]", so in my test, I added an Index column in Query Editor mode, each time, I returned the last row (max index number) per Participant_ID per Unique_Test_ID.

 

Please refer to below measure formulas:

Measure1 =
CALCULATE (
    SUM ( 'Learning Sessions'[Seconds_Spend] ),
    ALLEXCEPT (
        'Learning Sessions',
        'Learning Sessions'[Participant_ID],
        'Learning Sessions'[Unique_Test_ID]
    )
)

Measure2 =
CALCULATE (
    SUM ( 'Learning Sessions'[Score] ),
    FILTER (
        'Learning Sessions',
        'Learning Sessions'[Index]
            = CALCULATE (
                MAX ( 'Learning Sessions'[Index] ),
                ALLEXCEPT (
                    'Learning Sessions',
                    'Learning Sessions'[Participant_ID],
                    'Learning Sessions'[Unique_Test_ID]
                )
            )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

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

 Hi Yuliana @v-yulgu-msft,

 

thank you very much!

The last row for [Score] is the max of [Single_Session_ID]. 😉

I have got further questions to your solutions.

  • Can I filter the outcome of Measure2, for example only scores higher than 50 and those count those?
  • Can I create the average of the outcome of measure 1 afterwards?

Hi @theitguy,

 


  • Can I filter the outcome of Measure2, for example only scores higher than 50 and those count those?

Do you want the table visual only show records where Measure2 is greater than 50? If so, you could apply the visual level filter as below:

1.PNG

 

 


  • Can I create the average of the outcome of measure 1 afterwards?

Do you want to get the average outcome per Participant_ID per Unique_Test_ID? If so, please modify the formula for Measure1:

Measure1 =
DIVIDE (
    CALCULATE (
        SUM ( 'Learning Sessions'[Seconds_Spend] ),
        ALLEXCEPT (
            'Learning Sessions',
            'Learning Sessions'[Participant_ID],
            'Learning Sessions'[Unique_Test_ID]
        )
    ),
    CALCULATE (
        COUNTROWS ( 'Learning Sessions' ),
        ALLEXCEPT (
            'Learning Sessions',
            'Learning Sessions'[Participant_ID],
            'Learning Sessions'[Unique_Test_ID]
        )
    )
)

2.PNG

 

Best regards,

Yuliana Gu

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

Hi @v-yulgu-msft,

 

thank you very much! But I am sorry, I think you got me wrong.:

 

  • Can I create the average of the outcome of measure 1 afterwards?

What I wanted to achieve was something like 

(197+974+439+1+78+201)/6. Summing up the aggregated tests sums and divive them bei the number of distinct test_IDs. So that I would actually get one number as an output afterwards

 

Same goes for 

  • Can I filter the outcome of Measure2, for example only scores higher than 50 and those count those?

I would like to count only the testIDs where the score is higher than 50. Therefore,  I would expect to see "2" as a result, in a card visualization for example.

 

 

Hardik
Continued Contributor
Continued Contributor

Hi @theitguy, Just a query here are all the fields coming from same table ? 

Hi @Hardik,

 

the fields from the Learning Sessions are from the same table, yes.

Orginally, I duplicated the Learning Sessions-Query (by referencing the original) and did the grouping in the new table which worked very well by using power query formulas. It was easy to group the sessions into tests and get the desired values.

 

But today I noticed, that my colleagues will find it hard to set filters in the future, because it is hard to identifiy whether they set filters for the table with the sessions or the aggregated table. Therefore, I am trying to do all the grouping stuff via measures.

 

EDIT: I think, the problem is that I have to aggregate the values I get again, so that I receive a scalar value. Even if I cannot determine value on a user-test basis then. I have tried the following, but even that does not work:

Seconds_Spend_Corrected_Grouped = VAR MYTempTable = SUMMARIZE(Learning_Sessions;Learning__Sessions["Unique_Test_ID];"Seconds";SUM(Learning__Sessions[Seconds_Spend])) RETURN AVERAGE(MyTempTable[Seconds])

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!

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.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.