Forum Discussion

SPaine86's avatar
SPaine86
Icon for Helper I rankHelper I
6 years ago

Create a SUMMARIZE table from related source

Hi everyone!

 

I am trying to create a SUMMARY table (of 'current data') which I can then append to 'historic data' using Union.

 

The issue I am having is that one of the columns I need to group by is in a related table, and it doesn't appear as an option when I start typing. If I force it in, I get the red underline which tells me that what I am doing is wrong.

 

I can achieve what I want quite easilyy in a table or matrix visualisation, so I believe it should be possible to do?

 

To simplify, I have three tables: Pupils, Attendance, and Group Memberships.

 

Each pupil has a one to many relationship with Attendance.

Each pupil has a one to many relationship with Group Memberships (the filter is both directions)..

 

Pupils contains:

UID (Unique ID)

Name

DoB

Pupil Year Group

etc

 

Attendance contains:

UID

Academic Year

Term

Number of sessions present

Number of sessions possible

 

Group contains:

UID

Characteristic Group

 

The summary table I want to create (called 2021 Attendance) will contain the following columns:

(Grouped by)

Academic Year

Term

Pupil Year Group

Characteristic Group

(Calculations)

Cohort (sum of UIDs)

Attendance (sum of number of sessions present / sum of number of sessions possible)

 

2021 Attendance = SUMMARIZE('Attendance', 'Attendance'[Academic Year], 'Attendance'[Term], 'Pupils'[Pupil Year Group], 'Group'[Characteristic Group], "Cohort", distinctcount([UID]), "Attendance", divide(sum([Present]), sum([Possible],0))

 

Can anyone see where I'm going wrong?

 

Thanks

 

 

Steve

3 Replies

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

    SPaine86 - Maybe use RELATED or RELATEDTABLE. Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

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

      I am sorry that I did not provide enough clarity.

       

      OK so here is some sample information:

       

      PUPILS table

      UIDNameDOBPupil Year Group
      A123Bob1/3/96Year 3
      A234Sally2/4/97Year 4
      A345Dave3/5/96Year 3
      A456Abdul4/6/96Year 3

       

      ATTENDANCE table

      UIDYearTermPresentPossible
      A1232021Term 150100
      A2342021Term 175100
      A3452021Term 1100100
      A4562021Term 190100
      A1232021Term 295100
      A2342021Term 2100100
      A3452021Term 2100100
      A4562021Term 295100

       

      GROUP table:

      UIDCharacteristic
      A123Left handed
      A123Black African
      A123Disadvantaged
      A123Born in Summer
      A234Right handed
      A234White British
      A234Not Disadvantaged
      A345Black African

      etc

       

      Each pupil is related to multiple groups.

       

      I want to produce a summary table which looks like:

      YearTermPupil Year GroupCharacteristicCohortAttendance
      2021Term 1Year 3Left handed1580.4
      2021Term 1Year 3Black African1390.8
      2021Term 1Year 3Disadvantaged537.7
      2021Term 1Year 3Born in Summer274.5
      2021Term 1Year 3Right handed180.6
      2021Term 1Year 3White British2779.5
      2021Term 1Year 3Not Disadvantaged31etc
      2021Term 1Year 4Left handed13 
      2021 Term 1Year 4 Black African18 
      2021 Term 1 Year 4Disadvantaged6 
      2021 Term 1 Year 4Born in Summeretc 
      2021 Term 1 Year 4Right handed  
       2021 Term 1 Year 4White British  
       2021 Term 1 Year 4Not Disadvantaged  

       

      The issue I have is adding the column 'Characteristic' to my SUMMARIZE function when I create a new table.

       

      The model is shaped like this:

       

      Pupil to Group - One to many (filter in both directions)

      Pupil to Attendance - One to many (filter left to right)

       

      Other tables which are related to the Pupil table do appear to work, but I am unable to add Characteristic into the summary. I have tried RELATED('Group'[Group]) but this is not recognised ("Function SUMMARIZE expects a column name as argument number").

       

      Is this more helpful?