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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
rivera11115
Regular Visitor

Dynamic card based on year slicer

Hi,

 

I want the dynamic card to read as follows:

Sales year between 2013 and 2016 -- only if a range of consecutive years are selected ex 2013,2014,2015 & 2016.

Sales year for 2012, 2014, 2015 and 2016 --random years

Sale year 2013 --one year

 

rivera11115_0-1678484702055.png

 

 

1 ACCEPTED SOLUTION

Hi..thank you so much for helping out.

Your code works for the first two scenarios (see original question) but when a single year is chosen the year repeats in the header twice.

rivera11115_0-1678545173895.png

I was able to tweek your code a little and it works great thank you so much!

DateRange =
VAR MaxYear =
    MAX ( 'Calendar'[Year])
VAR MinYear =
    MIN ( 'Calendar'[Year] )
VAR Difference = ( MaxYear - MinYear ) + 1
VAR TotalSelectedValues =
    DISTINCTCOUNT ( 'Calendar'[Year] )
RETURN
IF(TotalSelectedValues= 1, "Sales Year " & CONCATENATEX (VALUES ( 'Calendar'[Year] ), 'Calendar'[Year], " " ),
    IF (
        Difference > TotalSelectedValues,
        "Sales Year for " & CONCATENATEX ( VALUES ('Calendar'[Year] ), 'Calendar'[Year], ", " ),
        IF (
            Difference = TotalSelectedValues,
            "Sales Year Between " & MinYear & " and " & MaxYear,
            IF ( HASONEVALUE ('Calendar'[Year]), SELECTEDVALUE ( 'Calendar'[Year] ) )
        )
    )
)

View solution in original post

5 REPLIES 5
Padycosmos
Solution Sage
Solution Sage

This vdeo illustrates how to create a Dynamic title, in addition to Rankx

https://www.youtube.com/watch?v=inJ3Yt7ay30

Anonymous
Not applicable

Hello @rivera11115 ,

You can try out by using the following measure

_Title = 
Var YearSeries = SUMX(
        SELECTCOLUMNS(
                GENERATESERIES(MIN(date[The_Year]),MAX(date[The_Year]),1),
                "Series",[Value]
                ),
            [Series]
        )
VAR T1 = CONCATENATEX(VALUES(date[The_Year]),date[The_Year],",")
VAR T2 = CONCATENATE(CONCATENATE(MIN(date[The_Year])," and "),MAX(date[The_Year]))
Var SelYears = SUMX(VALUES(date[The_Year]),date[The_Year])

VAR FinalTitle = IF ( YearSeries=SelYears ,CONCATENATE(" between ",T2),CONCATENATE(" for ",T1))
RETURN 
CONCATENATE("Sales year",FinalTitle)


Output

MuskanAgarwal_0-1678523731118.pngMuskanAgarwal_1-1678523743394.png


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



Hi..thank you so much for helping out.

Your code works for the first two scenarios (see original question) but when a single year is chosen the year repeats in the header twice.

rivera11115_0-1678545173895.png

 

rajulshah
Super User
Super User

@rivera11115 ,

 

Please use the following dax measure:

SelectedYearValues =
VAR MaxYear =
    MAX ( Dates[Year] )
VAR MinYear =
    MIN ( Dates[Year] )
VAR Difference = ( MaxYear - MinYear ) + 1
VAR TotalSelectedValues =
    DISTINCTCOUNT ( Dates[Year] )
RETURN
    IF (
        Difference > TotalSelectedValues,
        CONCATENATEX ( VALUES ( Dates[Year] ), Dates[Year], ", " ),
        IF (
            Difference = TotalSelectedValues,
            "Between " & MinYear & " and " & MaxYear,
            IF ( HASONEVALUE ( Dates[Year] ), SELECTEDVALUE ( Dates[Year] ) )
        )
    )

 

Please let me know if this didn't help.

Hi..thank you so much for helping out.

Your code works for the first two scenarios (see original question) but when a single year is chosen the year repeats in the header twice.

rivera11115_0-1678545173895.png

I was able to tweek your code a little and it works great thank you so much!

DateRange =
VAR MaxYear =
    MAX ( 'Calendar'[Year])
VAR MinYear =
    MIN ( 'Calendar'[Year] )
VAR Difference = ( MaxYear - MinYear ) + 1
VAR TotalSelectedValues =
    DISTINCTCOUNT ( 'Calendar'[Year] )
RETURN
IF(TotalSelectedValues= 1, "Sales Year " & CONCATENATEX (VALUES ( 'Calendar'[Year] ), 'Calendar'[Year], " " ),
    IF (
        Difference > TotalSelectedValues,
        "Sales Year for " & CONCATENATEX ( VALUES ('Calendar'[Year] ), 'Calendar'[Year], ", " ),
        IF (
            Difference = TotalSelectedValues,
            "Sales Year Between " & MinYear & " and " & MaxYear,
            IF ( HASONEVALUE ('Calendar'[Year]), SELECTEDVALUE ( 'Calendar'[Year] ) )
        )
    )
)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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