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

Clusterd Column Chart: how to get full year and a month next together

Hi,

 

In my report, I have a clustered column chart like the one below. The green bar displays values for 2018 (full year) and the black one shows data for 2019 YTD.

 

Example1.JPG

I would like to be able to show a single month as an additional third column to eventually come to something like this:

Example2.JPG

The legend is built on a column computed with:

Legend = IF('TestData'[Year] = "2018" ; "2018 FY" ; IF('TestData'[Year] = "2019" && 'TestData'[Month] = "5" ; "2019.05" ; IF('TestData'[Year] = "2019" ; "2019 YTD" ; 'TestData'[Year])))

 

But the way I managed to do it now, isn't exactly what I need. The black column isn't showing all the data for 2019 anymore since May is taken out of it and displayed in the yellow column. 

 
Is there a way to get it right? Where green is 2018 (full year), black is 2019 YTD and yellow is the last full month available?
 
Additionally, it would be great if there could be a way that this last full month could change automatically. Meaning that nobody has to go in manually to change the month of the yellow column. Today, the yellow column should display May. As of the 1st of July, the yellow column should display June.
 
Hope this makes sense.
 
Thanks,
 
Annelies
 
 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Based on test, I found my formula return multiple data types(number and text) that power bi can't recognize column data type. I modify my formula to change output data type to text to fix this issue:

Legend = 
VAR _lastYear =
    MAXX ( ALL ( Table1 ), [Year] )
VAR _lastMonth =
    MAXX ( ALL ( Table1 ), [Month] )
RETURN
    IF (
        'Table1'[Year] = _lastYear - 1,
        [Year] & " FY",
        IF (
            'Table1'[Year] = _lastYear
                && 'Table1'[Month] = _lastMonth,
            [Year] & "." & [Month],
            IF ( 'Table1'[Year] = _lastYear, [Year] & "2019 YTD", 'Table1'[Year]&"" )
        )
    )

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

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Anonymous ,

You can try to use below calculated column formula if it suitable for your requirement:

Legend =
VAR _lastYear =
    MAXX ( ALL ( TestData ); [Year] )
VAR _lastMonth =
    MAXX ( ALL ( TestData ); [Month] )
RETURN
    IF (
        'TestData'[Year] = _lastYear - 1;
        [Year] & " FY";
        IF (
            'TestData'[Year] = _lastYear
                && 'TestData'[Month] = _lastMonth;
            [Year] & "." & [Month];
            IF ( 'TestData'[Year] = _lastYear; [Year] & "2019 YTD"; 'TestData'[Year] )
        )
    )

If above not help, please share some sample data for test.

Regards,

Xiaoxin Sheng

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

Hi @v-shex-msft ,

 

Thank you for your reply. It's always great to learn new DAX-code.

 

I fully understand the logic behind it, but I can't get it to work though. It gives me the following error message: "Expressions that yield variant data-type cannot be used to define calculated columns."

 

I figured the cause might be that we're adding text to a number, so I tried changing the data type for [Year] and [Month] to text. After which I get this: "DAX comparison operations do not support comparing values of type Text with values of type Number. Consider using the VALUE of FORMAT function to convert one of the values." Probably due to the "_lastYear - 1" part?


Any ideas on how to solve this?

 

Hope this works as sample data:

 

DateYearMonthCategoryValue
1/01/201820181Bleu10
20/01/201820181Red5
24/01/201820181Bleu3
1/02/201820182Green3
20/02/201820182Purple10
24/02/201820182Red1
1/03/201820183Bleu6
20/03/201820183Green2
24/03/201820183Purple2
1/04/201820184Purple8
20/04/201820184Red9
24/04/201820184Green2
1/05/201820185Bleu4
20/05/201820185Bleu1
24/05/201820185Green6
1/06/201820186Purple6
20/06/201820186Purple3
24/06/201820186Red7
1/07/201820187Green8
20/07/201820187Red6
24/07/201820187Bleu1
1/08/201820188Red2
20/08/201820188Purple9
24/08/201820188Green4
1/09/201820189Purple8
20/09/201820189Bleu2
24/09/201820189Green7
1/10/2018201810Purple10
20/10/2018201810Red2
24/10/2018201810Bleu4
1/11/2018201811Green5
20/11/2018201811Purple9
24/11/2018201811Purple5
1/12/2018201812Red8
20/12/2018201812Red1
24/12/2018201812Red6
1/01/201920191Green10
20/01/201920191Green9
24/01/201920191Bleu8
1/02/201920192Purple10
20/02/201920192Purple2
24/02/201920192Bleu8
1/03/201920193Bleu2
20/03/201920193Green3
24/03/201920193Red1
1/04/201920194Purple3
20/04/201920194Purple6
24/04/201920194Green10
1/05/201920195Bleu6
20/05/201920195Red3
24/05/201920195Green6
1/06/201920196Red8
20/06/201920196Bleu6
24/06/201920196Purple9

 

Hi @Anonymous ,

Based on test, I found my formula return multiple data types(number and text) that power bi can't recognize column data type. I modify my formula to change output data type to text to fix this issue:

Legend = 
VAR _lastYear =
    MAXX ( ALL ( Table1 ), [Year] )
VAR _lastMonth =
    MAXX ( ALL ( Table1 ), [Month] )
RETURN
    IF (
        'Table1'[Year] = _lastYear - 1,
        [Year] & " FY",
        IF (
            'Table1'[Year] = _lastYear
                && 'Table1'[Month] = _lastMonth,
            [Year] & "." & [Month],
            IF ( 'Table1'[Year] = _lastYear, [Year] & "2019 YTD", 'Table1'[Year]&"" )
        )
    )

Regards,

Xiaoxin Sheng

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

Hi @v-shex-msft ,

It works perfectly, thank you very much!

Cheers,

Annelies

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.