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
Anonymous
Not applicable

Combo chart with relative axis

Hi there, 

 

I'm looking for a solution to a problem that might be much simpler than what i'm imagining.

The thing is, i want to create a really simple combo chart where sales amount is described by bars and sales units by lines.

 

Something like this:


Example.jpg

 

Now, the tricky part (for me) is making a relative axis depending on today's date. I tried creating a calculated column in my dates table, but seems to be is not that straight forward. For example, if today's date is March the 7th, 'Last month' should get the sales from february, and 'Last 3 months' the sales from november, december and january.

 

Creating calculated measures for 'last month' and 'last 3 months' is not an alternative, because there will be no conection between the bars or lines to show increase or decrease among those periods.

 

 

 

So... any ideas on how to create this chart?

 

Thanks!!Robot Very Happy

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Dale, thanks a lot! 

 

I did a little change to it and it worked perfectly.

I just replicated two more variables, because 'last3months' wouldn't get month-3 and month-2. Then i used a nested if and voilá!

 

This are the changes:

x-axis = 
VAR yyyymm =
    FORMAT ( [FECHA], "yyyymm" )
VAR lastmonth =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY (), -1 , MONTH ),
        ALL ( FECHAS )
    )
VAR month4 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -4 , MONTH )
    )
VAR month3 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -3 , MONTH )
    )    
VAR month2 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -2 , MONTH )
    )       
  
RETURN
    IF (
        yyyymm = lastmonth,
        "lastmonth",
        IF ( yyyymm = month4, "last3month", IF(yyyymm = month3, "last3month", IF(yyyymm = month2, "last3month", "other" )))
    )

You truly are a Super Contributor Robot LOL

 

Thanks again,

View solution in original post

2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Seems easy, but very tricky. Please try the formula below. I changed the date of my computer to test. It works fine.

x-axis =
VAR yyyymm =
    FORMAT ( [Date], "yyyymm" )
VAR lastmonth =
    CALCULATE (
        FORMAT ( MIN ( [Date] ), "yyyymm" ),
        DATESINPERIOD ( 'Calendar'[Date], TODAY (), -1, MONTH ),
        ALL ( 'Calendar' )
    )
VAR last3months =
    CALCULATE (
        FORMAT ( MIN ( [Date] ), "yyyymm" ),
        DATESINPERIOD ( 'Calendar'[Date], TODAY () - DAY ( TODAY () ), -4, MONTH )
    )
RETURN
    IF (
        yyyymm = lastmonth,
        "lastmonth",
        IF ( yyyymm = last3months, "last3month", "Other" )
    )

Combo_chart_with_relative_axis

 

 

Best Regards,

Dale

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

Dale, thanks a lot! 

 

I did a little change to it and it worked perfectly.

I just replicated two more variables, because 'last3months' wouldn't get month-3 and month-2. Then i used a nested if and voilá!

 

This are the changes:

x-axis = 
VAR yyyymm =
    FORMAT ( [FECHA], "yyyymm" )
VAR lastmonth =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY (), -1 , MONTH ),
        ALL ( FECHAS )
    )
VAR month4 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -4 , MONTH )
    )
VAR month3 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -3 , MONTH )
    )    
VAR month2 =
    CALCULATE (
        FORMAT ( MIN ( [FECHA] ), "yyyymm" ),
        DATESINPERIOD ( FECHAS[FECHA], TODAY () - DAY ( TODAY () ), -2 , MONTH )
    )       
  
RETURN
    IF (
        yyyymm = lastmonth,
        "lastmonth",
        IF ( yyyymm = month4, "last3month", IF(yyyymm = month3, "last3month", IF(yyyymm = month2, "last3month", "other" )))
    )

You truly are a Super Contributor Robot LOL

 

Thanks again,

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.