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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
gunicotra
Helper II
Helper II

Calculate with multiple conditions and with measure

Hi to everyone,

I am trying to calculate the count of some elements undependently from the slicer and using a measure for an index.

Basically I have:

- Year (slicer) = 2021

- [MonthUpDate] is a measure that gives the last Month of data collected.

 

I wouold like to have the count of elements for year 2018 and for the months March.

The solution I guessed is:

 

CALCULATE(sum('Table'[COUNTER]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
filter(all('Table'[DATA_IN]),month('Table'[DATA_IN])=[MonthUpDate]))

 

The formula is not wring, but I got no elements counted (i.e.: result = null) while in reality I have 14.500 elements in that year/month.

May enyone give some hints?

Thanks in advance

 

 

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @gunicotra ,

 

Can you give me some sample data and the results you want to get? Or share me with your pbix file from your Onedrive for Business.

 

You can create a calendar table and use the date column to create a date slicer to filter month and year.

 

Best Regards,

Stephen Tao

 

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

amitchandak
Super User
Super User

@gunicotra , if you have date. With help from date table

 

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

 

or

 

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

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi amitchandak,

your first answer made me think at a different solution which worked well!

 

CALCULATE(sum('Table'[Counter]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
DATESINPERIOD('Table'[DATE_IN],[MinDatePY],-30,DAY)
)/4

 

With [MinDatePY] = DATE(2018,MONTH(NOW()),DAY(NOW())) is a new measure that brings back to 2018

 

Thus thank you for the hint 😉

Hi Kudos,

unfortunately this did not give the right solution. I still got no error, but "null" as value.

In order to provide more elements I can say that skipping the measure, give the right solution:

CALCULATE(sum('Table'[COUNTER]),
filter(all('Table'[YEAR]),'Table'[YEAR]=2018),
filter(all('Table'[DATA_IN]),month('Table'[DATA_IN])=3))

 

However in this case I just applicable to March.

 

I read that filtering with ALL( column).... should be the right answer to using a measure as index. But I don't understand whiy this is not working in my case.


Thanks

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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