Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Dear community,
I am struggling with an YTD calculation.
I need to calculate [# of leads] YTD only when [number of lead generators] > 0.
Tried few different codes and this is what I came up with (not displaying the result I expected).
What I expect is to see 25 + 18 + 15 and this is the code I used:
Solved! Go to Solution.
@johnt75 - I made it!
I created Measure Test with this code:
Thank you for your help and wih you all the best,
Atanas
I think I know what the problem is. Your Year Month column is using a different column as the sort by column, correct? Try
Test =
VAR AllMonths =
CALCULATETABLE (
SUMMARIZE (
'Calendar',
'Calendar'[Month & Year],
'Calendar'[Year month sort column]
),
DATESYTD ( 'Calendar'[Date], "Oct-31" )
)
VAR ValidMonths =
FILTER ( AllMonths, [Number Of Lead Generators] > 0 )
VAR Result =
CALCULATE ( [# Of Leads], REMOVEFILTERS ( 'Calendar' ), ValidMonths )
RETURN
Result
@johnt75 - I made it!
I created Measure Test with this code:
Thank you for your help and wih you all the best,
Atanas
Try
Test =
VAR AllMonths =
CALCULATETABLE (
VALUES ( 'Calendar'[Month & Year] ),
DATESYTD ( 'Calendar'[Date], "Oct-31" )
)
VAR ValidMonths =
FILTER ( AllMonths, [Number Of Lead Generators] > 0 )
VAR Result =
SUMX ( ValidMonths, [# Of Leads] )
RETURN
Result
I've tried it, but this is the result I got:
I think
Test =
VAR AllMonths =
CALCULATETABLE (
VALUES ( 'Calendar'[Month & Year] ),
DATESYTD ( 'Calendar'[Date], "Oct-31" )
)
VAR ValidMonths =
FILTER ( AllMonths, [Number Of Lead Generators] > 0 )
VAR Result =
CALCULATE ( [# Of Leads], REMOVEFILTERS ( 'Calendar' ), ValidMonths )
RETURN
Result
should do it
Same result unfortunately.
I'd expect to see 43 in Jul, but the code gets me 18 😞
Can you change the measure to first return the COUNTROWS of AllMonths and then the COUNTROWS of ValidMonths? Just want to identify which bit isn't working as intended.
Dear @johnt75
This is what I get when I return the count Rows of AllMonths:
And this is what I get when I return the countrows of ValidMonths:
Thank you one more time.
PS: I am getting a bit desperate on that calculation 😞
Atanas
I think I know what the problem is. Your Year Month column is using a different column as the sort by column, correct? Try
Test =
VAR AllMonths =
CALCULATETABLE (
SUMMARIZE (
'Calendar',
'Calendar'[Month & Year],
'Calendar'[Year month sort column]
),
DATESYTD ( 'Calendar'[Date], "Oct-31" )
)
VAR ValidMonths =
FILTER ( AllMonths, [Number Of Lead Generators] > 0 )
VAR Result =
CALCULATE ( [# Of Leads], REMOVEFILTERS ( 'Calendar' ), ValidMonths )
RETURN
Result
@johnt75 - That is 100% true. My month and year column is sorted by another column in order to be shown chronologically, and not alphabetically.
Your code worked flawlessly this time around:
Thank you so much for your help!
It is deeply appreciated!
All due respect,
Atanas
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
26 | |
10 | |
10 | |
9 | |
6 |