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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BunzietheBoo
New Member

[DAX] How to apply a multiplier on a Parameter based on a Date and another parameter

Hello all, 

First post for me here on a problem I have for a few days.
I am working on a dashboard displaying sales data for a bunch of shops.
To be properly interpreted, the sales numbers has to be adjusted by a multiplier.
This multiplier is different for every shop and is changing through time.

The multiplier values are stored in a "Multiplier" table  :

ShopIDDateMultiplier
101.01.20181
101.01.20201.2
201.01.20181.1
302.03.20191.05


On the other end, the sales values are stored in another "Sales"table :

ShopIDDateSalesNb
101.01.2018545
201.01.2018362
301.01.2018421
102.01.2018532
202.01.2018350
(...)(...)(...)


I also have a "DateTable" where I store all the date input of my data model and a "Shop" Table.
Regarding the relationships : 
"DateTable"    1 ---->-----*    "Sales"
"Shop"            1 ---->---- *    "Sales"
"Shop"            1 ---->-----*    "Multiplier"
"DateTable"    1 ---->---- *    "Multiplier"

My goal is to have a measure that return for a given asset and for a given date, the multiplier that should be apply to the Sales number.


This measure will then be used in a SWITCH measure to allow the user to pick if they want the adjusted number or not.
Good luck and tell me if you want more information !

1 ACCEPTED SOLUTION

Some DAX to add it as a calculated column to Sales would be 

Multiplier = 
VAR _Shop = Sales[ShopID]
VAR _Date = Sales[Date]
VAR _Latest = 
TOPN(
    1,
    FILTER(Multiplier, Multiplier[Date] <= _Date && Multiplier[ShopID] = _Shop),
    Multiplier[Date], DESC
)
RETURN
MAXX(_Latest, Multiplier[Multiplier])

The measure is then relatively simple

Sales with Multiplier = 
SUMX(
    Sales,
    Sales[SalesNb] * Sales[Multiplier]
)

View solution in original post

2 REPLIES 2
PaulOlding
Solution Sage
Solution Sage

Hi @BunzietheBoo 

Have you thought about adding the Multiplier to the Sales table, either in Power Query or the source?

From a modelling perspective that's where it should go if you're going to use it in a measure.

The resulting measure will also perform better - something to consider if you have a large amount of data.

Some DAX to add it as a calculated column to Sales would be 

Multiplier = 
VAR _Shop = Sales[ShopID]
VAR _Date = Sales[Date]
VAR _Latest = 
TOPN(
    1,
    FILTER(Multiplier, Multiplier[Date] <= _Date && Multiplier[ShopID] = _Shop),
    Multiplier[Date], DESC
)
RETURN
MAXX(_Latest, Multiplier[Multiplier])

The measure is then relatively simple

Sales with Multiplier = 
SUMX(
    Sales,
    Sales[SalesNb] * Sales[Multiplier]
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors