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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kamalAnalyst
New Member

Dynamic Changinng column Name in Table Viz

I have created two measure current year sales and previous year Sales and I have year Slicer 

I have created table Customer wise current year and previous year sales 

What I want is 
When I select year then current year column name should show as selected year and previous year as (year - 1) eg year = 2023 then previous year = 2022

But If I dont select any year then It should give me only one column of overall sales customer wise and also If I select start year ie First Year then There wont be any Previous Year Data then should get only one column of current year 

??
Please help me in this since stuck since 2 days and there is presentation in 10 Days ....Dynamic Column Name Changing.png

1 ACCEPTED SOLUTION
samratpbi
Super User
Super User

Hi,

its a bit tricky, however you can achieve that with few measures.
First, I created a sample table like below:

samratpbi_0-1713457755837.png

Then created below measures:

Total Sales = SUM(DynCol[Sales])
Total Sales Prev Yr =
CALCULATE(
    [Total Sales],
    DynCol[Year] = SELECTEDVALUE(DynCol[Year]) - 1
)
Then create a slicer on year column and put values into a matrix visual
samratpbi_1-1713457917987.png

Now, for your column header, create 3 more measures:

Current Year =
IF(
    NOT(ISFILTERED(DynCol[Year])),
    "Overall",
    SELECTEDVALUE(DynCol[Year])
)
 
MinYear =
CALCULATE(
    MIN(DynCol[Year]),
    ALL(DynCol)
)
Prev Year =
SWITCH(
    TRUE(),
    NOT(ISFILTERED(DynCol[Year]))," ",
    SELECTEDVALUE(DynCol[Year]) = [MinYear]," ",
    SELECTEDVALUE(DynCol[Year]) - 1
)
then MinYear is a measure to be used iin Prev Year measure.
Now, put the current year and prev year measures into card visuals and put on top of the columns.
It would look like below:
When nothing selected:
samratpbi_2-1713458152155.png
When 2022 selected:
samratpbi_3-1713458206646.png

when 2023 selected:

samratpbi_4-1713458236360.png

If this resolves your problem, then please mark it as Solution, Thanks!

View solution in original post

1 REPLY 1
samratpbi
Super User
Super User

Hi,

its a bit tricky, however you can achieve that with few measures.
First, I created a sample table like below:

samratpbi_0-1713457755837.png

Then created below measures:

Total Sales = SUM(DynCol[Sales])
Total Sales Prev Yr =
CALCULATE(
    [Total Sales],
    DynCol[Year] = SELECTEDVALUE(DynCol[Year]) - 1
)
Then create a slicer on year column and put values into a matrix visual
samratpbi_1-1713457917987.png

Now, for your column header, create 3 more measures:

Current Year =
IF(
    NOT(ISFILTERED(DynCol[Year])),
    "Overall",
    SELECTEDVALUE(DynCol[Year])
)
 
MinYear =
CALCULATE(
    MIN(DynCol[Year]),
    ALL(DynCol)
)
Prev Year =
SWITCH(
    TRUE(),
    NOT(ISFILTERED(DynCol[Year]))," ",
    SELECTEDVALUE(DynCol[Year]) = [MinYear]," ",
    SELECTEDVALUE(DynCol[Year]) - 1
)
then MinYear is a measure to be used iin Prev Year measure.
Now, put the current year and prev year measures into card visuals and put on top of the columns.
It would look like below:
When nothing selected:
samratpbi_2-1713458152155.png
When 2022 selected:
samratpbi_3-1713458206646.png

when 2023 selected:

samratpbi_4-1713458236360.png

If this resolves your problem, then please mark it as Solution, Thanks!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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