Forum Discussion

kamran's avatar
kamran
Frequent Visitor
9 years ago

Need conditional Count/Running Total from a Data Set

Hi Gurus

 

I'm new to Power BI and we are in transition planning from Excel Pivots to Power BI dashboards. I've been given a test case to check the compatibility of Power BI with our scenario. I've following data (which is pulled from SSAS cubes):

 

 

AgeBand	ProgramYear	ProgramCode	Trimester	StudentNumber
15-20	2015		Psychology		T1	111111
15-20	2015		Psychology		T1	111112
15-20	2015		Psychology		T1	111113
21-25	2015		Psychology		T1	111114
21-25	2015		Psychology		T1	111115
21-25	2015		Psychology		T1	111116
26-30	2015		Psychology		T1	111117
26-30	2015		Psychology		T1	111118
26-30	2015		Psychology		T1	111119
15-20	2015		Psychology		T2	111110
15-20	2015		Psychology		T2	111112
15-20	2015		Psychology		T2	111113
21-25	2015		Psychology		T2	111121
21-25	2015		Psychology		T2	111122
21-25	2015		Psychology		T2	111115
21-25	2015		Psychology		T2	111116
26-30	2015		Psychology		T2	111117
26-30	2015		Psychology		T2	111118
26-30	2015		Psychology		T2	111119
15-20	2015		Psychology		T3	111123
15-20	2015		IT			T1	111111
15-20	2015		IT			T2	111111
15-20	2015		IT			T3	111111
15-20	2015		IT			T3	111112

 

From this data I need two kinds of outputs.

 

First one is:

 

Psychology
Year2015   
TrimesterT1T2T3Psychology Total
AgeBandNew EnrolmentsRe-EnrolmentsTotal EnrolmentsNew EnrolmentsRe-EnrolmentsTotal EnrolmentsNew EnrolmentsRe-EnrolmentsTotal EnrolmentsNew EnrolmentsRe-EnrolmentsTotal Enrolments
15-20303123123549
21-25303223000527
26-30303033000336

 

I am planning to build this output throuh Matrix layout by having Trimesters in columns whereas user will select Year & Program from Slicers. But I can't calculate New & Re-Enrolments figures in Power BI.

 

The second output I need is:

 

YearProgramTrimesterAgeNew EnrolmentsNew Running TotalRe-EnrolmentsRe-Enrolments Running Total
2015PsychologyT115-203300
2015PsychologyT121-253600
2015PsychologyT126-303900
2015PsychologyT215-2011022
2015PsychologyT221-2521224
2015PsychologyT226-3001237
2015PsychologyT315-2011329
2015ITT115-201100
2015ITT215-200111
2015ITT315-201212

 

 

Same problem I've in this output is to differentiate between New & Re-Enrolment fiures and then to have their runnings totals.

 

Can you please help me to build up this report?

3 Replies

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft Employee

    Hi kamran,

    >>But I can't calculate New & Re-Enrolments figures in Power BI.

    After research, I am still confusing how to calculate the New and Re-Enrolments. For example, in output table2, how to get 1 in 15-20 age, T2Trimester, 'Psychology'ProgramCode, 2015?

    In addition, in Excel Pivot, you get the result by creating calculated or measure? You can also create calculated column and measure in Power BI.

    Could you please share more details for further analysis?

    Best Regards,
    Angelia

    • kamran's avatar
      kamran
      Frequent Visitor

      Hi Angelia

       

      Thanks a lot for looking into my problem.

       

      >>After research, I am still confusing how to calculate the New and Re-Enrolments. For example, in output table2, how to get 1 in 15-20 age, T2Trimester, 'Psychology'ProgramCode, 2015?

      New Enrolment means, any student appearing for the first time in a program (Psychology or IT) in our data set is New. If it appears 2nd or 3rd time in subsequent years or trimesters but in the same program, it should be considered as Re-Enroling student.

       

      >> In addition, in Excel Pivot, you get the result by creating calculated or measure? You can also create calculated column and measure in Power BI.

      I've generated this output with SQL and I tried to generate BI report with Advanced option of Direct Query, but there are limitations on using SQL query as a data source e.g use of Common Table Expression in the Query, application of Query parameters etc.

       

      Moreover, I found DAX formulae for Running Totals but these are straight running total for the whole data set. What if I wish to break/group running totals for each Qualification Programs?

      • v-huizhn-msft's avatar
        v-huizhn-msft
        Microsoft Employee

        Hi kamran,

        Many fucntions are not used in Direct Query model. I recommand you load you data using import model.

        Then you can create measures using the formulas, and get expected result.

        New Enrolments = CALCULATE(COUNTA(Test[StudentNumber]),FILTER(Test,Test[time]=1))
        
        Total = CALCULATE(Test[New Enrolments],FILTER(ALL(Test),Test[Index]<=MAX(Test[Index])))

        Then create a matrix visual shown the first screenshot, and second visual shown in the following second screenshot.



        If you have any question, please let me know.

        Best Regards,
        Angelia