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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
CupidC
Helper II
Helper II

Behavior of GENERATE and VARIABLE in DAX

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.

CupidC_0-1719806335029.png

 

 

Any insights or suggust readings on why this is happening would be greatly appreciated!

2 REPLIES 2
Anonymous
Not applicable

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

rajendraongole1
Super User
Super User

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!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.