Forum Discussion

BenediktW's avatar
BenediktW
Advocate I
2 years ago
Solved

Inherit Values from previous rows

Dear Community,

 

I am facing an issue regarding an inheriting logic. I have a table in my canvas environment (example attached with the key columns), which contains certain subcategories. Those are having an descending index, which will start new for every subcategory. Additionally, I have one value column, which includes for every first row of an subcategory (highest index) an 0 or 1 value. 

With the calculation I want to fill in a new column for every row in the respective subcategory this "first row value". 

 

One special case is, that in the column inherit flag the indentificator "MSCOP" can occur, which turns over the inherting value, as it was previously 0 then its now 1 and the other way round. 

 

Summarization: I want to have an inheriting logic of values (0 or 1), which is firstly just inheriting the value from the previous row. When the indetificators "First row" or "MSCOP" occur, a re-evalution of the to-inherit value should happen. 

 

I tried with some code attached below, but wasnt successfull so far.

 

Thank you very much

 

 

 

VAR CurrentSubcategory = MyTable[Subcategory]
VAR CurrentValue = MyTable[First Row Value]
VAR InheritFlag = MyTable[Inherit_Flag]
VAR CurrentRow = MyTable[Index.1]

VAR InheritedValue =
    CALCULATE(
        MAXX(
            FILTER(
                ALL(MyTable),
                MyTable[Subcategory]] = CurrentSubcategory
                && MyTable[First Row Value] <> BLANK()
                && MyTable[Index.1] < CurrentRow
            ),
            MyTable[First Row Value]
        ),
        ALLEXCEPT(MyTablet, MyTable[Subcategory]])
    )

VAR NewSubcategory =
    NOT (
        MyTable[Subcategory]] = CALCULATE(
            VALUES(MyTable[Subcategory]]),
            MyTable[Index.1] = CurrentRow
        )
    )

RETURN
    IF(
        OR(
            ISBLANK(CurrentValue),
            InheritFlag = "MSCOP"
        ) || NewSubcategory,
        InheritedValue + IF(InheritFlag = "MSCOP", -1, 0),
        BLANK()
    )

 

 

 

 

Subcategory columnIndex.1First Row valueInherit_FlagWished Result
Subkategory  150First Row0
Subkategory 14  0
Subkategory 13 MSCOP1
Subkategory 12  1
Subkategory 11  1
Subkategory 251First Row1
Subkategory 24  1
Subkategory 23  1
Subkategory 22  1
Subkategory 21  1
Subkategory 350First Row0
Subkategory 34  0
Subkategory 33 MSCOP1
Subkategory 32  1
Subkategory 31  

1

5 Replies

  • Hi BenediktW,

    If "MSCOP" can appear only once, you can try such a calculated column:

    In plain text:

    Result = 
    VAR CurrentSubcategory = [Subcategory column]
    VAR CurrentIndex = [Index.1]
    VAR InitialValue = MINX ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory ), [First Row value] )
    VAR FinalValue = ABS ( COUNTROWS ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory && [Index.1] >= CurrentIndex && [Inherit_Flag] = "MSCOP" ) ) - InitialValue )
    RETURN FinalValue

     

    Best Regards,

    Alexander

    My YouTube vlog in English

    My YouTube vlog in Russian

    • BenediktW's avatar
      BenediktW
      Advocate I

      Hi,

       

      thank you very much already! That is working better than my approaches so far. Unfortunately, it can happen that the "MSCOP" Identifikator shows up multiple times per Subkategory. 

      • barritown's avatar
        barritown
        Solution Sage

        Okay, try this modification then:

        Result = 
        VAR CurrentSubcategory = [Subcategory column]
        VAR CurrentIndex = [Index.1]
        VAR InitialValue = MINX ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory ), [First Row value] )
        VAR FinalValue = ABS ( MOD ( COUNTROWS ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory && [Index.1] >= CurrentIndex && [Inherit_Flag] = "MSCOP" ) ), 2 ) - InitialValue )
        RETURN FinalValue

        Best Regards,

        Alexander

        My YouTube vlog in English

        My YouTube vlog in Russian