Forum Discussion

AJ42's avatar
AJ42
Icon for Helper I rankHelper I
5 years ago

Calculations including rows with no data

Hello 

 

I am working on a piece of work to identify students who are not engaging in remote learning. I am using the Microsoft Graph API's to pull usage reports from Microsoft 365. I would like to get day by day active usage of the service and more importantly show students that have now been active.

 

I have 2 tables the first table is an export from the School records systems and the other is the report from the graph. I have been able to match users based on the unique id which is synced for all users but im unable to get the calculations to work as i need them. 

 

Below is how my data looks

 

Table 1 (Student data system report)

NameID
User 11234
User 21235
User 31236
User 41237
User 51238
User 61239

 

Table 2 (Microsoft Graph usage Report)

UPNIDReportDateActive Date
[email protected]123405/01/202105/01/2021
[email protected]123505/01/202121/12/2020
[email protected]123705/01/202105/01/2021
[email protected]123905/01/202104/01/2021

 

The issue im having is that now all students are showing in the usage report which i assume is due to them never being active. I need to record these students as not active. Below is the result i am trying to achieve. 

 

NameIDUPNActiveNot ActiveActive Filter
User 11234[email protected]1 Active
User 21235[email protected] 1Not Active
User 31236  1Not Active
User 41237[email protected]1 Active
User 51238  1Not Active
User 61239[email protected] 1Not Active
   24 

 

I am able to acheive the active count using the formular below, Which i can also tweak to get the count for non active students that exist in Table 2, however i can't get this to work when i unhide blank rows. 

 

Active 

 

 

Active = IF(Table2[TeamsActiveDate] = Table2[ReportDate],1,BLANK())

 

 

 

Not Active

 

 

Active = IF(TAble2[TeamsActiveDate] <> Table2[ReportDate],1,BLANK())

 

 

 

Any help on this would be amazing

10 Replies

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, AJ42 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table 1:

    Table 2:

     

    There is a relationship between two tables. You may create measures as below.

    Active = 
    var tab = 
    SUMMARIZE(
        'Table 1',
        'Table 1'[Name],
        'Table 1'[ID],
        "Result",
        IF(
            MAX('Table 2'[ReportDate])=MAX('Table 2'[Active Date])&&MAX('Table 2'[UPN])<>"",
            1
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )
    Inactive = 
    var tab = 
    SUMMARIZE(
        'Table 1',
        'Table 1'[Name],
        'Table 1'[ID],
        "Result",
        IF(
            MAX('Table 2'[ReportDate])<>MAX('Table 2'[Active Date])||MAX('Table 2'[UPN])="",
            1
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )
    Active Filter = 
    var tab = 
    SUMMARIZE(
        'Table 1',
        'Table 1'[Name],
        'Table 1'[ID],
        "Result",
        IF(
            MAX('Table 2'[ReportDate])=MAX('Table 2'[Active Date])&&MAX('Table 2'[UPN])<>"",
            "Active",
            "Inactive"
        )
    )
    return
    IF(
        ISFILTERED('Table 1'[Name]),
        MAXX(
            tab,
            [Result]
        )
    )

     

    Result:

     

    Best Regards

    Allan

     

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

     

    • AJ42's avatar
      AJ42
      Icon for Helper I rankHelper I

      Hi v-alq-msft 

       

      Thanks you so much for that, that has almost got me there, the issue i have now which i should have put in the original post really is that i have multiple reports dates. Im pulling data from the MS graph and dumping it into SQL. So table 2 will have a ReportDate for each day. I will then need to filter based on the ReportDate but include users where they are not in that days report.

       

      This would all be so much easier if MS Graph would report all users rather than (my guess) users that have ever been active.  

      • v-alq-msft's avatar
        v-alq-msft
        Icon for Community Support rankCommunity Support

        Hi, AJ42 

         

        Could you show us some sample data and expected result with OneDrive for Business? Do mask sensitive data before uploading. Thanks.

         

        Best Regards

        Allan

  • amitchandak, Thanks for getting back to me so promptly. I think the main issue i have is i have more users in Table1 than i do in Table2. I have enebled show items with no data but i need to be able to record those as not active. Do you know if it is possible to include calculations for blank cells? 

  • PC2790's avatar
    PC2790
    Icon for Community Champion rankCommunity Champion

    Hi,

     

    I tried implementing using the data you provided and it can be done using M query. The code is as below:

     

    let
        MergedTable_ = Table.NestedJoin(UserTable, {"ID"}, UsageTable, {"ID"}, "UsageTable", JoinKind.LeftOuter),
        #"Expanded UsageTable" = Table.ExpandTableColumn(MergedTable_, "UsageTable", {"UPN"}, {"UsageTable.UPN"}),
        addedUsage_= List.Difference(UserTable[ID], UsageTable[ID]),
         T1_ = Table.AddColumn(Table.SelectRows(UserTable, each List.Contains(addedUsage_, [ID])), "Active Filter", each "Not active", type text),
         T2_ = Table.AddColumn(Table.SelectRows(#"Expanded UsageTable", each not List.Contains(addedUsage_, [ID])), "Active Filter", each "Active", type text),
         FinalList = Table.Combine({T1_,T2_})
    in
        FinalList

    The result looks something like this:

     

     

    The other two columns for Active and Inactive cna be easily added based on ACtive filter column.Let me know if you want me to do it.

    I hope this solves your purpose

     

    • AJ42's avatar
      AJ42
      Icon for Helper I rankHelper I

      HI PC2790 

       

      Thanks you so much that looks like what i am looking for. Do you have details on how to apply this? Is this a new table or a measure? Not done anything with M query before.

       

      Thanks

      • PC2790's avatar
        PC2790
        Icon for Community Champion rankCommunity Champion

        Here are the steps:

        1) Load the two tables as usual.

        2) Go to 'Transform Data' to open Query Editor

        3) Click on 'New Source' and select Blan Query.

        4) Delete the existing code and replace it with the code I provided.

         

        And your job is done. You can further tweak accordig to your requirement.

         

        I hope this solves your purpose. Please mark my post as a solution.