Forum Discussion

jrojasuk's avatar
jrojasuk
Regular Visitor
9 years ago

DAX reference calculated column previous calculated value, different row, within self formula

Hi,

 

I wonder if there is any way to reference a different (previous) calculated value within the same column in a different row within the general formula of the calculated column. When I try doing this I get the generic "circular reference error", even though I have keys and dates to be able to clearly differenciate the row context. 

 

So basically I would like to be able to do something like this ( easily doable in Excel and the rest ):

 

A2 := if ( A1 = "Green", "Red", "Green" ) 

 

Note that the formula here is not important. What I would like to do is to reference a different value in a different row context for the same column.

 

Any ideas? Would a calculated measure help instead ? 

 

Thanks for your help.

 

Jose

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I don't think you can write a formula that refers to itself.

     

    ColumnName = TableName[ColumnName] + 1

     

    ...for instance is an invalid formula. I think the only way to get what you want would be to make some sort of secondary helper column to refer back to. The specifics of how that would work depend entirely on the specifics of what you want to do.

    • jrojasuk's avatar
      jrojasuk
      Regular Visitor

      Yes, thanks, but surely, with all those structural concepts of Row Context and Filter Context, there must be a way of extracting a previously calculated unique row/column value within the same column range. After all a calculated column is supposed to be a "fixed" permanent entity added to the table. That is what makes it different from a measure among other things.

       

      What is the architectural design thought around this? Surely this is not a new odd requirement, but something that happens quite frequently all over the place. 

       

      After all Excel itself easily supports this concept, not to mention other competitor's products.

       

      Of course, there is always a hack around it, but that should not be the way. In the worse case scenario I could calculate everythig in either Excel or SQL and just load the final data into the BI for presentation and colouring. But then what is the added value?  

       

      Wish list feature?

       

      Jose 

      • Anonymous's avatar
        Anonymous
        Not applicable

        Excel doesn't support this, because you're talking about two different things. You can write an Excel formula that refers to another row in the same column, but you can't write a formula that refers to itself. This isn't Excel. A column in Excel is a canvas with locations, and you can put different formulas in different locations. A column in Excel can contain potentially a million unique formulas. And the column itself exists independent of the formulas. If there are no formulas in the cells, the column is still there. A column in a database isn't the same thing. The column is defined by a single formula, and the formula is the same for every row.

         

        You can write a column formula that looks at other rows in the same table. Whatever result you're trying to get is probably possible by a different method. This isn't Excel and it isn't really meant to work like Excel. It has far more in common with a database than it does with a spreadsheet.

         

        What are the actual results you're trying to get?

  • ncraft's avatar
    ncraft
    Frequent Visitor

    This may be of some help: Cthulhu - Microsoft Power BI Community

    On a different post, I had a question about calculating cumulative consecutive values and I couldnt develop a solution my my own. User Greg_Deckler helped me out a lot by providing the link above. It invloves a method where by a temporary table is generated and then the calculated column references that table, which - at least in my case - gets around the circular reference issue. Maybe it will be helpful for you aswell?

    Best of Luck.