Forum Discussion

aatish178's avatar
aatish178
Helper IV
2 years ago
Solved

subtracting previous row value from current row dynamically in Table visual

quantumudit Hi Udit,I have a below dataset:

 

FYStudentIDStudentNameGenderStatusClassDivision
FY1911palashMAbsentDIV A
FY1912akashMAbsentDIV A
FY1913vikasMAbsentDIV A
FY1914subhasMAbsentDIV A
FY1915kailasMAbsentDIV B
FY1916sureshMAbsentDIV B
FY1917rameshMAbsentDIV B
FY1918ankeshMPresentDIV B
FY1919maheshMPresentDIV B
FY1920pritiFPresentDIV B
FY1921dipaliFPresentDIV B
FY2022abcdFPresentDIV B
FY2023swatiFPresentDIV B
FY2024vaishnaviFPresentDIV B
FY2025akankshaFPresentDIV B
FY2026pallaviFPresentDIV B
FY2027ramaFPresentDIV B
FY2028radhaFPresentDIV B
FY2029sumedhMAdmission CanNA
FY2030shaileshMAdmission CanNA
FY2031venkatMAdmission CanNA
FY2032pandiMAdmission CanNA
FY2033reddeppaMAdmission CanNA
FY2034vishnuMAdmission CanNA
FY2035raviMAdmission CanNA
FY2036kiranFAdmission CanNA
FY2037anupamaFAdmission CanNA
FY2038rehanMOn leaveDIV B
FY2039rijwanMOn leaveDIV B
FY2040akbarMOn leaveDIV C
FY2041atliMOn leaveDIV C
FY2042vetriMOn leaveDIV C
FY2143thomasMWaitingYet to update
FY2144peterMWaitingYet to update
FY2145fredrikMWaitingYet to update
FY2146venkateshMWaitingYet to update
FY2147dineshMWaitingYet to update
FY2148chaitanyaMWaitingYet to update
FY2149rockyMWaitingYet to update

once I loaded this data in PBI then I want to get below output where difference column is actually a difference of count of studentID for each FY: Scenario 1:

 

 

Scenario 2:

Power BI Result:

Here I am suspecting since I have calculated the difference as a calculated column the result is static., I want your help to make it dynamic., I guess with measure that can be possible. can you please help me with measure expression?

 

Kind Regards,

Aatish

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi aatish178 

     

    First, we need to ensure we have a measure that calculates the total count of StudentID for each FY.

    Total Students = COUNT('Table'[StudentID])

     

    Next, we'll create a measure that calculates the difference in the count of StudentID between each FY and the previous FY.

    Difference = 
    VAR CurrentFY = MAX('Table'[FY])
    VAR PreviousFY = CurrentFY - 1
    VAR CurrentFYCount = CALCULATE([Total Students], 'Table'[FY] = CurrentFY)
    VAR PreviousFYCount = CALCULATE([Total Students], 'Table'[FY] = PreviousFY)
    RETURN CurrentFYCount - PreviousFYCount
    % = 
    VAR CurrentFY = MAX('Table'[FY])
    VAR PreviousFY = CurrentFY - 1
    VAR CurrentFYCount = CALCULATE([Total Students], 'Table'[FY] = CurrentFY)
    VAR PreviousFYCount = CALCULATE([Total Students], 'Table'[FY] = PreviousFY)
    RETURN (CurrentFYCount - PreviousFYCount)/PreviousFYCount

     

     

    This is the result you want:


     

     

    Best Regards,

    Jayleny

     

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

     

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi aatish178 

     

    First, we need to ensure we have a measure that calculates the total count of StudentID for each FY.

    Total Students = COUNT('Table'[StudentID])

     

    Next, we'll create a measure that calculates the difference in the count of StudentID between each FY and the previous FY.

    Difference = 
    VAR CurrentFY = MAX('Table'[FY])
    VAR PreviousFY = CurrentFY - 1
    VAR CurrentFYCount = CALCULATE([Total Students], 'Table'[FY] = CurrentFY)
    VAR PreviousFYCount = CALCULATE([Total Students], 'Table'[FY] = PreviousFY)
    RETURN CurrentFYCount - PreviousFYCount
    % = 
    VAR CurrentFY = MAX('Table'[FY])
    VAR PreviousFY = CurrentFY - 1
    VAR CurrentFYCount = CALCULATE([Total Students], 'Table'[FY] = CurrentFY)
    VAR PreviousFYCount = CALCULATE([Total Students], 'Table'[FY] = PreviousFY)
    RETURN (CurrentFYCount - PreviousFYCount)/PreviousFYCount

     

     

    This is the result you want:


     

     

    Best Regards,

    Jayleny

     

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

     

     

    • aatish178's avatar
      aatish178
      Helper IV

      Hi Jayleny,

      Thanks the solution is working as expected. The only change I did is I used Right(Max(FY),2) to fetch only number for further subtraction and it worked.

      Thanks once again.

  • Hi,

    Do you have a proper Date column?  If no, then do you have a Year and Month column?  Also, from which month does every FY start?