The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone,
I'm struggling to understand the behavior of GENERATE or VARIABLE in DAX.
I'm using the Contoso model as an example to compute the first three months' sales of a product.
First method: I declare a variable within the same measure to generate the dates for the three-month period.
Second method: I generate a table listing the dates for the first three months of sales for a product using the exact same formula as in the first method. I create a calculated table, then use the generated table as a filter argument in CALCULATE.
The two methods seem almost identical: one stores a temporary table in a variable, while the second generates an actual table in the model. However, the first method shows the expected result, whereas the second method does not.
Any insights or suggust readings on why this is happening would be greatly appreciated!
Hi @CupidC ,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information and description to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
Hi @CupidC - Please try below measure
Sales3MO =
VAR Filterproddates3MonthsVAR =
GENERATE (
VALUES ('Product'[FirstSaleDate]),
DATESINPERIOD ('Date'[Date], MAX('Product'[FirstSaleDate]), 3, MONTH)
)
VAR Sales3M =
CALCULATE ([Sales Amount], Filterproddates3MonthsVAR)
RETURN
Sales3M
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |