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
AndrejZitnay
Post Patron
Post Patron

Slicer to show data only if I have there data for last 13 months

Hello all,

I have my data set where I am showing distance travel per each vehicle for last 13 months.

I am using Calendar table where I have slicer for last 13 mohths.

I don't have problem with .

 

My data Calendar - I have slicer to filter last 13 moths.

 

AndrejZitnay_5-1633430452408.png

 

AndrejZitnay_1-1633429748963.png

Now I need to show data only if there are data for last 13 months.

 

Vehicle A might have  resutls only for latest 6 months

AndrejZitnay_2-1633429842679.png

 

Vehicle B might have results for full last 13 monhts

 

AndrejZitnay_3-1633429881237.png

 

I need to avoid vehicles/resutls if there aren't data for last 13 months. 

Is there way to do that?

I have distances in my DistanceTable and I link that to MasterCalendar via Date.

Each row is daily entry for one vehicle for one day.


I need to find way to find slicer / fitler to show only vehicles if there is some distance entry in each month of last 13 months.

 

Or another way around. I need to exclude vehicles if there aren't data in each month for last 13 moths.

 

AndrejZitnay_4-1633430366665.png

 

Would you be so kind and help me out?

 

Thanks.

 

Andrej

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @AndrejZitnay ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a calculated column in the fact table to get the yearmonth

YearMonth = VALUE(CONCATENATE(YEAR('Table'[Month]),FORMAT('Table'[Month],"MM")))

2. Create a measure as below to judge whether the vehiche include the data from last 13 months: if yes, return 1. otherwise,  return 0.

Note: I just go back 13 months based on the current date...

Has the data for last 13 months = 
VAR _countofmonths =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[YearMonth] ),
        ALLEXCEPT ( 'Table', 'Table'[Vehicle] ),
        DATESBETWEEN (
            'Table'[Month],
            EOMONTH ( TODAY (), -14 ) + 1,
            EOMONTH ( TODAY (), -1 )
        )
    )
RETURN
    IF ( _countofmonths < 13, 0, 1 )

3. Create visual level filter with condition (Has the data for last 13 months is 1)

yingyinr_0-1633681896234.png

Best Regards

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

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @AndrejZitnay ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a calculated column in the fact table to get the yearmonth

YearMonth = VALUE(CONCATENATE(YEAR('Table'[Month]),FORMAT('Table'[Month],"MM")))

2. Create a measure as below to judge whether the vehiche include the data from last 13 months: if yes, return 1. otherwise,  return 0.

Note: I just go back 13 months based on the current date...

Has the data for last 13 months = 
VAR _countofmonths =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[YearMonth] ),
        ALLEXCEPT ( 'Table', 'Table'[Vehicle] ),
        DATESBETWEEN (
            'Table'[Month],
            EOMONTH ( TODAY (), -14 ) + 1,
            EOMONTH ( TODAY (), -1 )
        )
    )
RETURN
    IF ( _countofmonths < 13, 0, 1 )

3. Create visual level filter with condition (Has the data for last 13 months is 1)

yingyinr_0-1633681896234.png

Best Regards

Community Support Team _ Rena
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

@AndrejZitnay , Create a measure like this and try

 

sumx(filter(summarize(Table, Table[Vehicle], "_1", DistinctCount(Table[Month year]), "_2", sum(Table[Distance Miles])),[_1]=13),[_2])

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.