Forum Discussion

konselz's avatar
konselz
Frequent Visitor
2 years ago
Solved

Calculate Recursively (?)

Hi everyone,   I am kind of stuck with calculating values recursively. See the attached pic.   Assume we only have / are provided with the first record (1 Jan 2023).  The rule is ColC = ColA - ...
  • barritown's avatar
    2 years ago

    Hi konselz,

    With the new rules it's better to solve task in Power Query I guess. If you want a clean solution, try asking gurus in the Power Query section of this forum.

    The not-very-clean amateurish solution from me may look like this:

    1) First, you go to Power Query and create an index column based on the Date column.

    2) Then you create a function like this:

     

    = ( i as number, a as number, b as number ) =>
    let 
        f = List.Generate(
            () => [j = 1, x = a, y = a - b],
            each [j] < i,
            each [y = [y] - 0.5*[x],
            x = [y],
            j = [j] + 1 ],
            each [y] )
    in
        if (i = 1) then a else List.Last(f)

     

    3) Then you add a custom column like this:

     

    = MyFunction ( [Index], List.Max(#"Changed Type"[ColA]), List.Max(#"Changed Type"[ColB]) )

     

    You will have ColA after that (ColB and ColC can be generated either via Power Query or via DAX):

    Check the file here - https://www.dropbox.com/scl/fi/cjue59hlw4jrm8olxtoh9/community-no-recursion-2.pbix?rlkey=lt0bdlbolq97iqku0rtxz13s8&dl=0

    Best Regards,

    Alexander

    My YouTube vlog in English

    My YouTube vlog in Russian