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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
bajimmy1983
Helper V
Helper V

Custom X Axis - Selected Months VS Others Months

Hi Community, how are you? 

 

So, I don't know if this is possible to accomplish with DAX, but the objective is simple in our "world", but in DAX is another talk.
I prepared a Simple Model if anyone wants to help.
I'm still trying, but maybe someone had the same custom business scenario resolved.

Objective

To show in a Clustered Column Chart just 2 Columns...
1- PERIOD = SUM of Sales for Selected Months in a Slicer for example;

2- OTHERS = SUM of Others Months NOT SELECTED;
3- No Months Selected = Show in X Axis normal Months from JAN to DEC.

Period_VS_Others.png


Thanks a lot in advance,
Jimmy

Jaderson Almeida
Business Coordinator
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

See attached.  This requires not one but two disconnected tables.

 

Total Vendas =
VAR t =
    MAX ( 'Table'[tick] )
RETURN
    IF (
        ISFILTERED ( sDate[Mês Abrev Proper v1] ),
        SWITCH (
            t,
            "Period",
                CALCULATE (
                    SUM ( fsales[Valor Venda] ),
                    TREATAS ( VALUES ( sDate[Data] ), dDate[Data] )
                ),
            "Others",
                CALCULATE (
                    SUM ( fsales[Valor Venda] ),
                    TREATAS ( VALUES ( sDate[Ano] ), dDate[Ano] )
                )
                    - CALCULATE (
                        SUM ( fsales[Valor Venda] ),
                        TREATAS ( VALUES ( sDate[Data] ), dDate[Data] )
                    )
        ),
        CALCULATE (
            SUM ( fsales[Valor Venda] ),
            TREATAS ( VALUES ( sDate[Data] ), dDate[Data] ),
            TREATAS ( { t }, dDate[Mês Abrev Proper v1] )
        )
    )

 

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

See attached.  This requires not one but two disconnected tables.

 

Total Vendas =
VAR t =
    MAX ( 'Table'[tick] )
RETURN
    IF (
        ISFILTERED ( sDate[Mês Abrev Proper v1] ),
        SWITCH (
            t,
            "Period",
                CALCULATE (
                    SUM ( fsales[Valor Venda] ),
                    TREATAS ( VALUES ( sDate[Data] ), dDate[Data] )
                ),
            "Others",
                CALCULATE (
                    SUM ( fsales[Valor Venda] ),
                    TREATAS ( VALUES ( sDate[Ano] ), dDate[Ano] )
                )
                    - CALCULATE (
                        SUM ( fsales[Valor Venda] ),
                        TREATAS ( VALUES ( sDate[Data] ), dDate[Data] )
                    )
        ),
        CALCULATE (
            SUM ( fsales[Valor Venda] ),
            TREATAS ( VALUES ( sDate[Data] ), dDate[Data] ),
            TREATAS ( { t }, dDate[Mês Abrev Proper v1] )
        )
    )

 

Hi @lbendlin, good afternoon (here in Brazil is 5:20pm).

 

First of all, A HUGE THANKS to You Man! Your Solution fit fantastic and worked fine for this scenario! 
I just made a very little adjustment to your original Measure in order to TOTALS in a Table or Matrix Visuals work fine as Chart. 

Here's the adjusted PBIX file

 

The only thing I really could not understand was the fact you used a wierd code (for me at least) in the FALSE stetament of IF Function. Could you please explain this part? Why did you used the Second TREATAS Function as second Filter of CALCULATE? I removed this second one and OK, values were not filtered, but I couldn't understand this second filter with TREATAS specially when you used "... t } ...

If it's possible to debug it and explain, it will be awesome, too! If, not, that's awesome same way! 

Thank you so much again for you time and effort to help me and others in the community.

 

Have a nice week bro! 

Jimmy

Jaderson Almeida
Business Coordinator

If you want you can rewrite

TREATAS ( { t }, dDate[Mês Abrev Proper v1] )

as

dDate[Mês Abrev Proper v1] = t

Wonderful @lbendlin! Pretty clear to me now and simple! I confess I barely use TREATAS Function, but one more lesson learned bro!

Thanks a lot,

Jimmy

Jaderson Almeida
Business Coordinator

You will want to learn about TREATAS, it is a very powerful function that will help you solve many filter scenarios.  It is also used behind the scenes for most of the visual queries.

Sure I will @lbendlin 😍

 

Jaderson Almeida
Business Coordinator

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.