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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
rbowen
Helper III
Helper III

Help With VAR Function, Or Should I Use A Different Approach?

I'm creating a basic table showing both YTD and MTD trial balance data for our current fiscal year. For now, I'm just focusing on the first 4 months of the FY. The YTD and MTD names are somewhat misleading because I'm not using a date table nor is there any date related information in the table I pull the raw data from other than the month name. Here's how I'm doing this so far:

 

The YTD value is created by first creating two calculated columns, one for debits, another for credits. I then create a third calculated column that calculates the difference between the debits and credits columns. This is my NetChange column. The final step in creating the YTD values is a measure that just sums the NetChange column:

YTD = CALCULATE(SUM(AcctBal[NetChange]))

 

Then, I get each month's YTD value by creating a measure to sum each month's YTD value:

 

SeptSum = CALCULATE(SUM(AcctBal[NetChange]),FILTER('AcctBal','AcctBal'[Month] = "September"))
OctSum = CALCULATE(SUM(AcctBal[NetChange]),FILTER('AcctBal','AcctBal'[Month] = "October"))
and so on thru December
 
Putting the YTD measure in my table, I get the correct YTD values for each month

 

rbowen_0-1736972646959.png

 

The trouble starts when I put the MTD values in the table. MTD values must be calculated as follows:

 

September, first month of the FY, will always equal the September YTD value.

OctoberMTD = OctoberYTD - SeptemberYTD  

NovemberMTD = NovemberYTD - OctoberYTD  

DecemberMTD = DecemberYTD - NovemberYTD  

 

My MTD measure is:

 

MTD =
VAR Month  = [SelectMonth]
VAR MTDSep = [SeptSum]
VAR MTDOct = [OctSum]-[SeptSum]
VAR MTDNov = [NovSum]-[OctSum]
VAR MTDDec = [DecSum]-[NovSum]
Return
IF (Month = "September", MTDSep,
IF (Month = "October", MTDOct,
IF (Month = "November", MTDNov,
IF (Month = "December", MTDDec))))
 
Here are what the MTD values should be:
 
rbowen_1-1736972913612.png

 

And here's how they come out in BI. September's is working but the rest are not. I've used the VAR function successfully in the past for similar types of operations, but it's not working now for some reason. I've got some piece of the syntax wrong obviously but what am I missing?

 

rbowen_2-1736973015630.png

 

4 REPLIES 4
Wilson_
Super User
Super User

Hi rbowen,

 

I strongly suggest changing your approach to one with a date table and a date in whatever table you're using now, instead of just a month name. That way, you can use date logic for your calculations instead of hardcoding a bunch of unintuitive logic.

 

It should be simple enough to turn your month into a date, especially if you have a year column too. A calculated column like the below should work:

Trial Balance Date = DATEVALUE ( Table1[Month] & " " & Table1[Year] )


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.

 




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

Proud to be a Super User!





Anonymous
Not applicable

Hi, @rbowen 

Update your measures as follows:

SeptSum = CALCULATE(SUM(AcctBal[NetChange]), FILTER(ALLSELECTED('AcctBal'[Month]), 'AcctBal'[Month] = "September"))

I added in every xxSum:

ALLSELECTED('AcctBal'[Month])

Here are the results:

vjianpengmsft_0-1736997831458.png

 

Best Regards

Jianpeng Li

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

 

Thank you Jianpeng Li, I was really hoping that would be the solution because of its simplicity. Unfortunately, it didn't change the MTD numbers at all and they're still the same as the YTD numbers. 

Anonymous
Not applicable

Hi, @rbowen 

Thank you very much for your feedback. Try this expression:

OctSum = CALCULATE(SUM(AcctBal[NetChange]), FILTER(ALLSELECTED('AcctBal'), 'AcctBal'[Month] = "October"))

vjianpengmsft_0-1737108352223.png

Make sure you are not affected by the row context. I've provided the PBIX file used this time below.

 

Best Regards

Jianpeng Li

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

 

 

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.

Top Solution Authors
Top Kudoed Authors