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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Cannot show value for previous month if current month is blank or has no data

Hi,

 

I work with data wherein I need to see performance of a policy for this year compared to performance of policy previous year. The policy numbers will be different for each year and hence have created a mapping of previous year policy. 

 

Issue I am facing is that when I select any existing policy, for eg it will have data for 4 months. But for previous policy it will have data for all 12 months. In the graph, when I put both measures, it shows data for only 4 months for both the policies. Ideally it should show for all 12 months.

 

I realised the issue is that for current policy data is for only 4 months and hence it is showing only 4 months for previous year as well. Due to technical challenges, I am not able to use Date table and will have to use month from data only. I tried adding +0, but didn't work.

 

Below are the 2 measures for selected year vs previous year.

 

selected_year = CALCULATE(DISTINCTCOUNT(claims_data[upload_id]),
FILTER(claims_data, claims_data'[status] = "Settled" ))

 

 

prev_year_value =

 

var prev_policy = MAX(claims_data[prev_policyno])

 

var ly_value = CALCULATE(DISTINCTCOUNT(claims_data[upload_id]),
claims_data[policyno] = prev_policy &&

 claims_data[status] = "Settled")

 

return
prev_year_value

 

As can be seen from the below 2 charts, chart on top shows data for only 4 months, whereas for previous policy there exists data for 12 months.

 

amit_darak_0-1692702884174.png

 

Regards,

Amit

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to create a Calendar table to help calculation.

Calendar = ADDCOLUMNS(CALENDARAUTO() ,"Year",YEAR([Date]),"Month",FORMAT([Date],"MMMM"),"MonthSort",MONTH([Date]))

I think you can sort [Month] column by [MonthSort] column.

For reference: Sort one column by another column in Power BI

Data model:

vrzhoumsft_0-1692864359170.png

Measure:

Selected_Year =
CALCULATE (
    DISTINCTCOUNT ( claims_data[upload_id] ),
    FILTER ( claims_data, claims_data[Status] = "Settled" )
)
Prev_Year_Value = 
CALCULATE (
    [Selected_Year],
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Year]
            = MAX ( 'Calendar'[Year] ) - 1
            && 'Calendar'[Month] = MAX ( 'Calendar'[Month] )
    )
)

Result in my sample is as below.

vrzhoumsft_1-1692864378622.png

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to create a Calendar table to help calculation.

Calendar = ADDCOLUMNS(CALENDARAUTO() ,"Year",YEAR([Date]),"Month",FORMAT([Date],"MMMM"),"MonthSort",MONTH([Date]))

I think you can sort [Month] column by [MonthSort] column.

For reference: Sort one column by another column in Power BI

Data model:

vrzhoumsft_0-1692864359170.png

Measure:

Selected_Year =
CALCULATE (
    DISTINCTCOUNT ( claims_data[upload_id] ),
    FILTER ( claims_data, claims_data[Status] = "Settled" )
)
Prev_Year_Value = 
CALCULATE (
    [Selected_Year],
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Year]
            = MAX ( 'Calendar'[Year] ) - 1
            && 'Calendar'[Month] = MAX ( 'Calendar'[Month] )
    )
)

Result in my sample is as below.

vrzhoumsft_1-1692864378622.png

 

Best Regards,
Rico Zhou

 

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

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.