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
GlynMThomas
Resolver I
Resolver I

!2 month rolling filter with 0's between the 12 months

I have a measure attached to a orphaned date table which allows my filter to display a 12 month period based on the date selected. This works fine, however any dates within the selected period that have no transactions don't show at all in my tables. I would like these to show as zero but obviously not show any dates outside this 12 month period. Every change I've tried so far doesn't work, it just pulls back all the other months I don't want to display. Is there a simple way I can adjust the measure below to do this?

 

Application Filter =
VAR CurrentDate = MAX('Filter Dates'[Date])
VAR PreviousDate = DATE(YEAR(CurrentDate), MONTH(CurrentDate) -11, DAY(CurrentDate) - DAY(CurrentDate) + 1)
VAR Result =
CALCULATE(
SUM(Applications[Total Application]),
FILTER(
Dates,
Dates[Date] >= PreviousDate && Dates[Date] <= CurrentDate
)
)
RETURN Result
1 ACCEPTED SOLUTION

HI @GlynMThomas,

You can use the following measure formula to achieve your requirement:

Measure = 
VAR CurrentDate =
    MAX ( 'Transactions'[Date] )
VAR PreviousDate =
    DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 11, 1 )
VAR range =
    CALENDAR ( PreviousDate, CurrentDate )
VAR Result =
    CALCULATE (
        SUM ( Transactions[Amount] ) + 0,
        FILTER (
            ALL ( Transactions ),
            Transactions[Date] IN range
                && Transactions[Date] <= MAX ( 'Calendar'[Date] )
        )
    )
RETURN
    IF ( MAX ( 'Calendar'[Date] ) IN range, Result )

Visual design:
1. Use transaction table date field as source of a slicer.
2. Create a table visual with calendar date, measure without aggregation modes.

Regards,

Xiaoxin Sheng

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

View solution in original post

12 REPLIES 12
amitchandak
Super User
Super User

@GlynMThomas , try to return 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.

RETURN Result+0 and check.

 

 

az38
Community Champion
Community Champion

Hi @GlynMThomas 

to show zeroes you need to create a calendar table like

CALENDARAUTO()

create relationships between calendar and your fact tables and put calendar table dates as X-axis into your visual


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

I already have a calendar table setup and tried to pull a zero across to fill in the gaps but it doesn't work.

 

Effectively I want the table to show like this:

 

MonthAmount
Jul-20200
Jun-200
May-20100
Apr-20200
Mar-200
Feb-200
Jan-200
Dec-19400
Nov-190
Oct-19300
Sep-19200
Aug-19100

 

But at the moment I get this:

 

MonthAmount
Jul-20200
May-20100
Apr-20200
Dec-19400
Oct-19300
Sep-19200
Aug-19100

 

So missing the table with zeros as they come through as blank because there aren't any transactions those months. The above shows when the filter is set to the most recent date.

az38
Community Champion
Community Champion

@GlynMThomas 

if you use the Calendar table as a Month column, it should be enough to set parameter Show items with no data as active for [Amount] column


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Unfortunately that then shows items outside of the measures date range as well which I don't want to see. At the moment the measure is setting anything outside the 12 month period as blank so it doesn't show, but this also means that anything inside that range that is blank as doesn't show. It's these values that I need to set to zero.

az38
Community Champion
Community Champion

@GlynMThomas 

change your measure to

Application Filter =
VAR CurrentDate = MAX('Filter Dates'[Date])
VAR PreviousDate = DATE(YEAR(CurrentDate), MONTH(CurrentDate) -11, DAY(CurrentDate) - DAY(CurrentDate) + 1)
VAR Result =
CALCULATE(
SUM(Applications[Total Application]),
FILTER(
Dates,
Dates[Date] >= PreviousDate && Dates[Date] <= CurrentDate
)
)
RETURN 
IF(ISBLANK(Result), 0, Result)

 

and you will see zeros


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thanks,

I've tried that though, it does bring zeros in but also then gives me everything outside the 12 month range which I don't want. The measure is basically filtering out everything that doesn't fall between 10/07/2020 and 10/07/2019. So when you select 10/07/2020 on the filter you get a table showing the amounts. It's quite fiddly as the behaviour of the measure causes issues.

HI @GlynMThomas,

Please provide some dummy data with expected results then we can test to coding format on it based on your requirements.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

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

Sure, here is a power bi file with the measure and table built.

 

https://drive.google.com/file/d/1SCJKXrPOxXQrW0LBF6UWWhgvCUnPf79E/view?usp=sharing

 

I'm just trying to show 12 months over the period selected by the filter and measure, so if there are no transactions in a month it should show as zero, however it should not show any months outside of the 12 month period.

Hi @GlynMThomas,

I can't view the shared link, it still required some additional permissions to access it, can you fix this?

Regards,

Xiaoxin Sheng

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

HI @GlynMThomas,

You can use the following measure formula to achieve your requirement:

Measure = 
VAR CurrentDate =
    MAX ( 'Transactions'[Date] )
VAR PreviousDate =
    DATE ( YEAR ( CurrentDate ), MONTH ( CurrentDate ) - 11, 1 )
VAR range =
    CALENDAR ( PreviousDate, CurrentDate )
VAR Result =
    CALCULATE (
        SUM ( Transactions[Amount] ) + 0,
        FILTER (
            ALL ( Transactions ),
            Transactions[Date] IN range
                && Transactions[Date] <= MAX ( 'Calendar'[Date] )
        )
    )
RETURN
    IF ( MAX ( 'Calendar'[Date] ) IN range, Result )

Visual design:
1. Use transaction table date field as source of a slicer.
2. Create a table visual with calendar date, measure without aggregation modes.

Regards,

Xiaoxin Sheng

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

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.