Forum Discussion
Generate as a variable within a Measure vs Table Help
Hey all,
Need help with a more efficient solution. I'm taking 'sales' and spreading them from the sales date by 12months. Meaning..the same sales number is spread evenly across 12months in order to setup a needed calculation. I'm currently doing this by generating a table and adding a column called 'Date' which provides all of the dates between the sales month and sales month +12. It works fine as a 'table'...but I was wondering if it would work faster as a nested variable within a measure...in order to lower the size of my model and just store it as a temp table within the measure and call out only what I need. Below is the generate code...
13 Replies
- ValtteriNCommunity Champion
Hi,
What kind of measure are you trying to use this sales in? You are correct that you can create a variable e.g.
Var _sales = DIVIDE([Sales],12)
return
Then simply refer to this in your measure. However depending on the visulization an calculation goals you have you might need to add/remove filters to this variable.- codyraptorResolver I
ValtteriN The reason I have to spread a sale by month evenly is I have to take the 1st and last month divided by 24 and all months in between divided by 12. I use 'generate' to push the sales out 12months...and I divide the 1st/last month by 24 else 12. The sum of these columns is what I'm after.
- ValtteriNCommunity Champion
Hi,
I understand your goal a bit better now. Then a suggestion: you could place your GENERATE DAX within a variable and calculate e.g. SUMX of that.
So something like this:
Var _vartable =GENERATE('biplanning Sales_Fcst',FILTER(CALENDAR(MIN('biplanning Sales_Fcst'[Accounting Month]),MAX('biplanning Sales_Fcst'[Deferred Date])),[Date] >= 'biplanning Sales_Fcst'[Accounting Month] && [Date] <= [Deferred Date] && DAY([Date])=1))Return
SUMX(_vartable,[calculated column])
You can add the calculated column to the vartable using ADDCOLUMNS
_vartable2 =
ADDCOLUMNS(_vartable,"Calculated Column","Place your logic here")
- v-robertq-msftCommunity Support
Hi,
Have you followed the DAX formula posted by AlexisOlson to find the solution to your problem?
If so, would you like to mark his reply as a solution so that others can learn from it too?
If you still have a problem, you can post some sample data(without sensitive data) and your expected result.
Thanks in advance!
How to Get Your Question Answered Quickly
Best Regards,
Community Support Team _Robert Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- codyraptorResolver I
The issue doesn't seem like it can be resolved by a measure...none of the suggestions work as I need to slice/filter by the dates that don't exist in the model. I think I'm limited to generating a table in order to do this. Please correct me if I'm wrong. Thanks!