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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply

Show only the value for the current Year

Hi everyone, 

 

I think I have a pretty simple question.

 

How do I have to change this measure in order to ONLY show values for the current year?

(I want to show the accumulated values of the current year only)

 

ShowOnlyValueForCurrentYear = 
VAR maxWeek = MAX('Calendar'[CalendarWeek])
VAR maxYear =  MAX('Calendar'[Year])
RETURN

CALCULATE(
    [Total Value Orders]; 
    ALL('Calendar'[CalendarWeek]);
    FILTER(ALL('Calendar'[Year]); 'Calendar'[Year] = maxYear);
    'Calendar'[CalendarWeek] <= maxWeek
)

 

 

screen.JPG

 

Thanks in advance for your help! This is a very helpful community 🙂

10 REPLIES 10
FarhanAhmed
Community Champion
Community Champion

In column series you are putting year and hence there are no filters applied on it, it is taking all available years.

 

Your measure will work correctly if you remove year from column series







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

Proud to be a Super User!




FarhanAhmed
Community Champion
Community Champion

If you want to show data for "Current year" you can use "Relative Date" Filtering against your date column in your visual to show current year data

relative Date filter.png







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

Proud to be a Super User!




Thanks for your hint @FarhanAhmed , but I would love to resolve it with DAX.

v-kelly-msft
Community Support
Community Support

Hi @robertomari2020 ,

 

Create a measure similarly as below:

 

 

Measure = 
Var _year=YEAR(TODAY())
Return
CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])&&YEAR('Table'[Date])=_year))

 

 

And you will see:

Annotation 2020-07-23 163007.png

 

In you case,you may try below dax expression:

ShowOnlyValueForCurrentYear = 
VAR maxWeek = CALCULATE(MAX('Calendar'[CalendarWeek]),ALL('Calendar'))
VAR maxYear =  CALCULATE(MAX('Calendar'[Year]),ALL('Calendar'))
RETURN

CALCULATE(
    [Total Value Orders]; 
    ALL('Calendar'[CalendarWeek]);
    FILTER(ALL('Calendar'[Year]); 'Calendar'[Year] = maxYear);
    'Calendar'[CalendarWeek] <= maxWeek
)

I made a sample .pbix file if needed.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

Hi @v-kelly-msft ,

you have attached a PBIX file to your reply, which you addressed to community.powerbi.com at the address...
Question: How can I upload a PBIX file to any of my posts in the community?
 
Regards FrankAT

Hi  @FrankAT ,

 

Just upload your .pbix file to Onedrive business and make a public link to share.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
 

Hi @v-kelly-msft , 

 

I tried your suggested code, but still getting the same problem. It takes the value of 2019 and also shows this in 2020. (but 2020 should be empty, because I only have values in 2019)

 

Unfortunately I also couldn't open your file - getting this error message:
Object reference not set to an instance of an object.

 

Thanks for your help so far!

Hi  @robertomari2020 ,

 

Could you pls upload your .pbix file to onedrive business and share the link with me?I will write the calculation according to your data.

Much appreciated.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@robertomari2020 , with a date table

 

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year 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))
//Only year vs Year, not a level below

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

 

Refer Power BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

for week refer

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi  @amitchandak,

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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