cancel
Showing results for
Did you mean:

## DAX variable how to

I have the following datasets:

1) Calendar

2) Actual: captures actual monthly sales

 Month Value Jan 1000 Feb 1200 Mar 800 etc

3) Forecast: captures forecast sales for remaining months.  Forecasts updated monthly.  eg. In Jan, 12 months' of forecast.  In Feb, 11 months' of forecast....etc

 ActMth ForecastMth Value Feb Mar 500 Feb Apr 600 Feb May 550 Feb Jun 700 Feb Jul 750 Feb Aug 500 Feb Sep 500 Feb Oct 500 Feb Nov 560 Feb Dec 580 Mar Apr 700 Mar May 800 Mar Jun 1000 Mar Jul 1100 Mar Aug 1200 Mar Sep 800 Mar Oct 900 Mar Nov 950 Mar Dec 1300

Relationship with Calendar set for #2-3.

I have a slicer in my excel worksheet to select "month" from Calendar.

I would like to achieve the following:

1) When I select "month" on the slicer, result should show me actual sales and forecast for remaining months accordingly.

eg. if selected month = Mar, report to show actual sales for Jan-Mar, forecast for Apr-Dec

if selected month = Feb, report to show actual sales for Jan-Feb, forecast for Mar-Dec

 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total Year Sales

Calculated measures created:

MTD Actual:=TOTALMTD(sum(Actual[Value]),'Calendar'[Date])

MTD Forecast:=calculate(TOTALMTD(sum(Forecast[Value]),'Calendar'[Date]),Forecast[ActMth]=3)

YTD Forecast:=calculate([YTD Actual],'Actual'[Date (Month Index)]<=3)+[MTD Forecast]

I have to manually change the month in the formula of "MTD forecast" and "YTD forecast".  Pls advise how to set these 2 measures variable according to slicer selected month.

3 REPLIES 3

Hi @bitbit ,

I'm not quite clear about the problem, as your description "Relationship with Calendar set for #2-3", do you mean the Calendar table have relationship with Actual table and also Calendar table have relationship with Forecast table? If so, which column are they connected, there's not date column in Actual and Forecast tables. Besides, I create a sample and attach it below, could you please reproduce your problem in my sample and send back.

Best regards,

Community Support Team_yanjiang

Pls advise solution to technical issue included in the excel file, link below:

Hi @bitbit ,

According to your description, here's my solution.

1. Create a Month table. Sort Month column by MonthNo column.

2.Create a measure.

``````Sales =
IF (
MAX ( 'Month'[MonthNo] ) <= SELECTEDVALUE ( 'Date'[Month] ),
MAXX (
FILTER ( Actual, MONTH ( 'Actual'[Date] ) = MAX ( 'Month'[MonthNo] ) ),
'Actual'[YTD]
),
IF (
MAX ( 'Month'[Month] ) <> "Total Year",
MAXX (
FILTER (
'Forecast',
'Forecast'[ActMth] = SELECTEDVALUE ( 'Date'[Month] )
&& MONTH ( 'Forecast'[Date] ) = MAX ( 'Month'[MonthNo] )
),
'Forecast'[Value]
),
SUMX (
FILTER ( Actual, MONTH ( 'Actual'[Date] ) <= SELECTEDVALUE ( 'Date'[Month] ) ),
'Actual'[YTD]
)
+ SUMX (
FILTER (
'Forecast',
'Forecast'[ActMth] = SELECTEDVALUE ( 'Date'[Month] )
&& MONTH ( 'Forecast'[Date] ) > SELECTEDVALUE ( 'Date'[Month] )
),
'Forecast'[Value]
)
)
)
``````

Put Month column from Month table in Matrix column and the measure in values, get the result:

I attach my sample below for your reference.

Best regards,

Community Support Team_yanjiang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Announcements

#### A Celebration of What We've Achieved--And Announcing Our Winners

As the sun sets on the #SummerofSolutions Challenge, it's time to reflect and celebrate! The journey we embarked upon together was not just about providing answers – it was about fostering a sense of community, encouraging collaboration, and unlocking the true potential of the Power Platform tools.   From the initial announcement to the final week's push, the Summer of Solutions Challenge has been a whirlwind of engagement and growth. It was a call to action for every member of our Power Platform community, urging them to contribute their expertise, engage in discussions, and elevate collective knowledge across the community as part of the low-code revolution.   Reflecting on the Impact As the challenge ends, it's essential to reflect on the impact it’s had across our Power Platform communities: Community Resilience: The challenge demonstrated the resilience of our community. Despite geographical distances and diverse backgrounds, we came together to contribute, learn, and collaborate. This resilience is the cornerstone of our collective strength.Diverse Expertise: The solutions shared during the challenge underscore the incredible expertise within our community. From intricate technical insights to creative problem-solving, our members showcased their diverse skill sets, enhancing our community's depth.Shared Learning: Solutions spurred shared learning. They provided opportunities for members to grasp new concepts, expand their horizons, and uncover the Power Platform tools' untapped potential. This learning ripple effect will continue to shape our growth. Empowerment: Solutions empowered community members. They validated their knowledge, boosted their confidence, and highlighted their contributions. Each solution shared was a step towards personal and communal empowerment. We are proud and thankful as we conclude the Summer of Solutions Challenge. The challenge showed the potential of teamwork, the benefit of knowledge-sharing, and the resilience of our Power Platform community. The solutions offered by each member are more than just answers; they are the expression of our shared commitment to innovation, growth, and progress!   Drum roll, Please... And now, without further ado, it's time to announce the winners who have risen above the rest in the Summer of Solutions Challenge!   These are the top community users and Super Users who have not only earned recognition but have become beacons of inspiration for us all.   Power Apps Community:  Community User Winner: @SpongYe Super User Winner: Pending Acceptance Power Automate Community:  Community User Winner: @trice602 Super User Winner: @Expiscornovus  Power Virtual Agents Community: Community User Winner: Pending AcceptanceSuper User: Pending Acceptance Power Pages Community: Community User Winner: @OOlashyn Super User Winner: @ChristianAbata   We are also pleased to announced two additional tickets that we are awarding to the Overall Top Solution providers in the following communities:    Power Apps: @LaurensM   Power Automate: @ManishSolanki    Thank you for making this challenge a resounding success. Your participation has reaffirmed the strength of our community and the boundless potential that lies within each of us. Let's keep the spirit of collaboration alive as we continue on this incredible journey in Power Platform together.Winners, we will see you in Vegas! Every other amazing solutions superstar, we will see you in the Community!Congratulations, everyone!