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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors