Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
PKPK90
Helper I
Helper I

Dynamic date filter based on slicer selection

Hi, what I want to change in my code is to use slicer selected value to filter OrderDate, right now I have date function which is hard coded. 
I have created Calendar table which can be useful but still do not know how to use it in correct way. PKPK90_0-1692262649761.png

 

My Measure:

WeightedAverageCost =
VAR tabl1 =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( PurchaseOrders, PurchaseOrders[Site_Item_Key]),
            "ItemExtendedCost", [M_ExtendedCost]
        ),
        FILTER(PurchaseOrders,PurchaseOrders[OrderDate]>DATE(2022,08,01)),  <- change to slicer value
        ALLSELECTED ( Items )
    )
VAR tabl2 =
    SELECTCOLUMNS (
    FILTER(
        PurchaseOrders,PurchaseOrders[OrderDate]>DATE(2022,08,01)), <- change to slicer value
        PurchaseOrders[Site_Item_Key],
        PurchaseOrders[Site],
        PurchaseOrders[Item],
        PurchaseOrders[OrderDate],
        PurchaseOrders[PurchaseOrder],
        PurchaseOrders[PurchaseOrderLine],
        PurchaseOrders[ItemCost],
        PurchaseOrders[ExtendedCost]
       
    )
VAR tabl3 =
    NATURALINNERJOIN ( tabl1, tabl2 )
VAR tabl4 =
    ADDCOLUMNS (
        tabl3,
        "%ofTotal", FORMAT ( DIVIDE ( [ExtendedCost], [ItemExtendedCost] ), "Percent" ),
        "WeightedItemCost", DIVIDE ( [ExtendedCost], [ItemExtendedCost] ) * PurchaseOrders[ItemCost]
    )
RETURN
    GROUPBY (
        tabl4,
        [Site],
        [Item],
        [Site_Item_Key],
        "TotalWeightedItemCost", SUMX ( CURRENTGROUP (), [WeightedItemCost] )
    )
1 REPLY 1
Prateek97
Resolver III
Resolver III

Hi,

Instead of 'FILTER(PurchaseOrders,PurchaseOrders[OrderDate]>DATE(2022,08,01))', you can try writing 
FILTER(PurchaseOrders,PurchaseOrders[OrderDate]>SELECTEDVALUE(Calendar[Date])).

 

Please mark as answer if works.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.