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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
kegoosse
Helper I
Helper I

Iterative average of growth ratio

Hi everyone,

 

In this file I'm trying to calculate survival rates of cohortes for the Belgian popualtion.

 

In the visualisation you can find 2 tables with 2 alternative versions for the calculation of the measure. Both are correct for a specific year, but I'm not getting the desired value for the total

 

kegoosse_0-1666958032879.png

 

For example, for cohort 1_0_44084 this should be 104.86%

i.e. average of :

98.8998.7893.81109.8135.63104.110097.84


The first measure (i.e. Average survival rate) isn't getting the desired result because the numerator and denominator aren't being iterated in the AVERAGEX function

 

Average survival rate = 
VAR HuidigeLeeftijd = MAX('Ruwe data Tellingen StatBel'[Leeftijd])
VAR VorigeLeeftijd = MAX('Ruwe data Tellingen StatBel'[Leeftijd]) - 1
VAR HuidigGeslacht = MAX('Ruwe data Tellingen StatBel'[Geslacht 0/1])
VAR HuidigGemeente = MAX('Ruwe data Tellingen StatBel'[Hoogste Refnis-code van gemeente])
VAR CohorteHuidig = HuidigeLeeftijd&"_"&HuidigGeslacht&"_"&HuidigGemeente
VAR CohorteVorig = VorigeLeeftijd&"_"&HuidigGeslacht&"_"&HuidigGemeente
VAR AantalHuidig = CALCULATE(
    SUM('Ruwe data Tellingen StatBel'[Aantal]),
    'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
)
VAR AantalVorig = CALCULATE(
    SUM('Ruwe data Tellingen StatBel'[Aantal]),
    'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
    SAMEPERIODLASTYEAR('Date'[Date])
)
VAR SurvivalRate = AantalHuidig/AantalVorig
RETURN
AVERAGEX( 
    SUMMARIZE(
        'Ruwe data Tellingen StatBel',
        'Date'[Year],
        'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)]
    ),
    SurvivalRate
)

 

kegoosse_1-1666958308215.png

 

However, when I add these parts in the AVERAGEX-function the total returns infinity (for measure Average survival rate 2). I'm not completely sure why this happens.

 

Average survival rate 2 = 
VAR HuidigeLeeftijd = MAX('Ruwe data Tellingen StatBel'[Leeftijd])
VAR VorigeLeeftijd = MAX('Ruwe data Tellingen StatBel'[Leeftijd]) - 1
VAR HuidigGeslacht = MAX('Ruwe data Tellingen StatBel'[Geslacht 0/1])
VAR HuidigGemeente = MAX('Ruwe data Tellingen StatBel'[Hoogste Refnis-code van gemeente])
VAR CohorteHuidig = HuidigeLeeftijd&"_"&HuidigGeslacht&"_"&HuidigGemeente
VAR CohorteVorig = VorigeLeeftijd&"_"&HuidigGeslacht&"_"&HuidigGemeente
VAR AantalHuidig = CALCULATE(
    SUM('Ruwe data Tellingen StatBel'[Aantal]),
    'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
)
VAR AantalVorig = CALCULATE(
    SUM('Ruwe data Tellingen StatBel'[Aantal]),
    'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
    SAMEPERIODLASTYEAR('Date'[Date])
)
VAR SurvivalRate = AantalHuidig/AantalVorig
RETURN
AVERAGEX(
    VALUES ('Date'[Year]),
    CALCULATE(
        SUM('Ruwe data Tellingen StatBel'[Aantal]),
        'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
    )
    /
    CALCULATE(
        SUM('Ruwe data Tellingen StatBel'[Aantal]),
        'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
        SAMEPERIODLASTYEAR('Date'[Date])
    )
)

 

Is someone able to explain what happens in the calculation of Average survival rate 2 when returning infinity? And even better, can someone adapt the measure so it returns for example 104.86% for cohort 1_0_44084?

Thanks in advance

Kenneth

1 ACCEPTED SOLUTION

Hi @kegoosse 
Please try with DIVIDE function

Average survival rate 2 =
AVERAGEX (
    VALUES ( 'Date'[Year] ),
    CALCULATE (
        VAR HuidigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] )
        VAR VorigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] ) - 1
        VAR HuidigGeslacht =
            MAX ( 'Ruwe data Tellingen StatBel'[Geslacht 0/1] )
        VAR HuidigGemeente =
            MAX ( 'Ruwe data Tellingen StatBel'[Hoogste Refnis-code van gemeente] )
        VAR CohorteHuidig = HuidigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR CohorteVorig = VorigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR AantalHuidig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
            )
        VAR AantalVorig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
                SAMEPERIODLASTYEAR ( 'Date'[Date] )
            )
        VAR SurvivalRate =
            DIVIDE ( AantalHuidig, AantalVorig )
        RETURN
            SurvivalRate
    )
)

 

 

View solution in original post

6 REPLIES 6
kegoosse
Helper I
Helper I

@tamerj1 - The Dax-code has been added for a while.
Do you have some other advice perhaps? The question has been online for a while, without any feedback. I assume I need to simplify the situation to get help?

@kegoosse 

Apologies for that. I haven't been notified for this change. You may try the following 

Average survival rate 2 =
AVERAGEX (
    VALUES ( 'Date'[Year] ),
    CALCULATE (
        VAR HuidigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] )
        VAR VorigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] ) - 1
        VAR HuidigGeslacht =
            MAX ( 'Ruwe data Tellingen StatBel'[Geslacht 0/1] )
        VAR HuidigGemeente =
            MAX ( 'Ruwe data Tellingen StatBel'[Hoogste Refnis-code van gemeente] )
        VAR CohorteHuidig = HuidigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR CohorteVorig = VorigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR AantalHuidig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
            )
        VAR AantalVorig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
                SAMEPERIODLASTYEAR ( 'Date'[Date] )
            )
        VAR SurvivalRate = AantalHuidig / AantalVorig
        RETURN
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
            )
                / CALCULATE (
                    SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                    'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
                    SAMEPERIODLASTYEAR ( 'Date'[Date] )
                )
    )
)

@tamerj1 

Thanks for the help. The suggested formula however returns the same result as the original one, i.e. correct values when reporting for a specific year, but returning infinty for the total value. Do you have any other suggestions?

kegoosse_0-1667466579927.png

 

Hi @kegoosse 
Please try with DIVIDE function

Average survival rate 2 =
AVERAGEX (
    VALUES ( 'Date'[Year] ),
    CALCULATE (
        VAR HuidigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] )
        VAR VorigeLeeftijd =
            MAX ( 'Ruwe data Tellingen StatBel'[Leeftijd] ) - 1
        VAR HuidigGeslacht =
            MAX ( 'Ruwe data Tellingen StatBel'[Geslacht 0/1] )
        VAR HuidigGemeente =
            MAX ( 'Ruwe data Tellingen StatBel'[Hoogste Refnis-code van gemeente] )
        VAR CohorteHuidig = HuidigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR CohorteVorig = VorigeLeeftijd & "_" & HuidigGeslacht & "_" & HuidigGemeente
        VAR AantalHuidig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteHuidig
            )
        VAR AantalVorig =
            CALCULATE (
                SUM ( 'Ruwe data Tellingen StatBel'[Aantal] ),
                'Ruwe data Tellingen StatBel'[Cohorte (leeftijd_geslacht_stad)] = CohorteVorig,
                SAMEPERIODLASTYEAR ( 'Date'[Date] )
            )
        VAR SurvivalRate =
            DIVIDE ( AantalHuidig, AantalVorig )
        RETURN
            SurvivalRate
    )
)

 

 

@tamerj1 - Thanks, this version worked as desired!

tamerj1
Super User
Super User

Hi @kegoosse 

would you please copy/pase the dax code?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.