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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Previous YTD with no date column

Hello,

 

I am trying to dd two measures to add running totals to this data, one by programme_period YTD and one for the previous ytd.

 

I have managed the YTD no problem but cannot seem to get the pytd working. I have tried adding year - 1 as a variable, within the filter context (using Max(year) -1) and various other combinations. 

 

If for example I am presenting this data in a table visual I would like to see the following 

 

Programme PeriodYTDPYTD
2001875,205451,941

 

Any help greatly appreciated!

 

Thanks,

 

Kevin

 

Screenshot.png

 

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this code:

 

pYTD =
VAR _p_YEAR = SELECTEDVALUE('Table (3)'[Programme Year]) - 1
VAR _p_MONTH = INT(RIGHT(_p_YEAR; 2) & RIGHT(SELECTEDVALUE('Table (3)'[Programme Period]); 2))
RETURN
CALCULATE(SUM('Table (3)'[Targeted]); FILTER(ALL('Table (3)'); 'Table (3)'[Programme Year] = _p_YEAR && 'Table (3)'[Programme Period] <= _p_MONTH))
 
Ricardo

 



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

Proud to be a Super User!



View solution in original post

6 REPLIES 6
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this code:

 

pYTD =
VAR _p_YEAR = SELECTEDVALUE('Table (3)'[Programme Year]) - 1
VAR _p_MONTH = INT(RIGHT(_p_YEAR; 2) & RIGHT(SELECTEDVALUE('Table (3)'[Programme Period]); 2))
RETURN
CALCULATE(SUM('Table (3)'[Targeted]); FILTER(ALL('Table (3)'); 'Table (3)'[Programme Year] = _p_YEAR && 'Table (3)'[Programme Period] <= _p_MONTH))
 
Ricardo

 



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

Proud to be a Super User!



Anonymous
Not applicable

Hi @camargos88 

 

Yes this works!

 

Any idea why these values don't work on cards? 

 

Kevin

 

HI @Anonymous,

Measures are calculated based on current row content and correspond category groups. Its row content equal to the whole table If you use it in the card. when you use selectedvalue function in this scenario, it will return multiple values.  (Your formula seems not to add option expressions to deal with multiple rows so it will return default value blank and cause the wrong filter result)
Regards,

Xiaoxin Sheng

 

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Greg_Deckler
Super User
Super User

Perhaps:

 

PYTD =

  VAR __Year = MAX('Table'[Year])

RETURN

  SUMX(FILTER(ALL('Table'),[Year] = __Year-1),[Some column])

 

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

First of all, create a year dimension and then try like

Prior Year= calculated([Measure],filter(All(Year),Year[Year]<=max(Year[Year])-1))

 

If you have a date, you can use with date dimension

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

 

Anonymous
Not applicable

Hi @amitchandak,

 

Thanks for your response. I don't have a Date Table, I'm hoping to figure out a way to do so with out one.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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