Forum Discussion

George1973's avatar
George1973
Icon for Helper V rankHelper V
4 years ago
Solved

Firstnonblank in virtual table

Hi, I'm stacked with using Firstnonblank function suing it for virtual table. Here is the virtual table code: AR MAct = UNION( ROW("MA",[Sold Prod Qnty],"RowNum",1), ROW("MA",[-1M],"RowNum",...
  • OwenAuger's avatar
    4 years ago

    Hi George1973 

    Are the [-1M], [-2M] etc measures applying a date shift of a given number of months to the [Sold Prodn Qty] measure (or similar)?

    I suspect there may be a more efficient way of handling this calculation, depending on what you want to do with RowNum. For example, you could apply FIRSTNONBLANK to months of a Date table, rather than referencing 24 different measures.

     

    Putting that to one side, to answer your original question, I would not suggest using the FIRSTNONBLANK function to find the first RowNum with nonblank MA. FIRSTNONBLANK is normally applied to a column of a physical table (which has lineage), and returns a 1-row 1-column table, retaining lineage of the original column. It is often used when you want to apply the resulting value as a filter in further calculations.

     

    In this case, you could more simply write:

    VAR LookupTable =
    UNION (
        ROW( "MA", [Sold Prod Qnty], "RowNum", 1 ),
        ROW( "MA", [-1M],"RowNum", 2 ),
        ROW( "MA", [-2M],"RowNum", 3 ),
       //...
        ROW( "MA", [-22M],"RowNum", 23 ),
        ROW( "MA", [-23M],"RowNum", 24 )
      )
    
    VAR FirstNonBlankRowNum =
        MINX ( LookupTable, IF ( NOT ISBLANK ( [MA] ), [RowNum] ) )

    Regards,

    Owen