Forum Discussion

Excellove15's avatar
Excellove15
Iron Contributor
Nov 30, 2023
Solved

Creating Dynamic Dax measure for a virtual table to filter table instead of calculated table(static)

Hi,   I have a below table in power bi: CreatedOn DataId Dataset Id Name Floor Area 28/10/2023 01:17 705756 1 Site 1 2342 28/10/2023 01:17 705753 2 Site 2 76829 28/10/2022 ...
  • SergeiBaklan's avatar
    Nov 30, 2023

    Excellove15 

    In the sample CreatedOn is returned as text, thus I added Createddate column as DATEVALUE() from it

    Bar date is added as measure

    Depends on your actual model, you may take it as SELECTEDVALUE() on Date table, whatever.

    Filtered table is calculated as

    Filtered Table = 
    VAR belowDate =
        FILTER ( Main, Main[CreatedDate] < [pDate] )
    VAR setRowId =
        ADDCOLUMNS (
            Main,
            "Id",
                ROWNUMBER (
                    belowdate,
                    ORDERBY ( Main[DataId], DESC ),
                    PARTITIONBY ( Main[Dataset Id] )
                )
        )
    VAR firstRows =
        FILTER ( setRowId, [Id] = 1 )
    VAR result =
        SELECTCOLUMNS (
            firstRows,
            "CreatedDate", Main[CreatedDate],
            "DataId", Main[DataId],
            "Dataset Id", Main[Dataset Id],
            "Name", Main[Name],
            "Floor Area", Main[Floor Area]
        )
    RETURN
        result

    Resulting table is

    You may return firstRows variables if don't care about extra Id column.

Resources