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
LisaK
Frequent Visitor

Need column chart that shows a measure for 3 different time periods

I have a request to build a column chart that shows the value of a measure for the last 7 days, last 28 days and last 365 days.  Any suggestions on the best way to approach this?  Below is an example of what I'm trying to reproduce (the line is the goal line)...

 
 

ChartImage.png

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @LisaK ,

According to my understanding ,you want to calculate sum of value based on different time periods, right?

You could use the following formula:

 

last7 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 7 )
)
last28 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 28 )
)
last365 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 365 )
)

 

Due to the measure cannot be used as X-axis, so you could create a new column with a value of "last 7" ,"last 28" and "last 365".Then use the column as X-axis to create a column chart.
 4.png
Then use Switch() to sum values.

 

 

sum value =
SWITCH (
    SELECTEDVALUE ( 'for X-axis'[last period] ),
    "last 7", [last7],
    "last 28", [last28],
    "last 365", [last365]
)

 

 

My visualizations look like this:
 
5.png

 

Is the result what you want? If not, please upload some data samples and expected output.
Please do mask sensitive data before uploading.
 
Best Regards,
Eyelyn Qin

View solution in original post

4 REPLIES 4
LisaK
Frequent Visitor

Great ideas!  Thanks everyone.  I'll give them a try.

v-eqin-msft
Community Support
Community Support

Hi @LisaK ,

According to my understanding ,you want to calculate sum of value based on different time periods, right?

You could use the following formula:

 

last7 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 7 )
)
last28 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 28 )
)
last365 =
CALCULATE (
    SUM ( 'Last Period'[Value] ),
    FILTER ( 'Last Period', DATEDIFF ( 'Last Period'[Date], NOW (), DAY ) <= 365 )
)

 

Due to the measure cannot be used as X-axis, so you could create a new column with a value of "last 7" ,"last 28" and "last 365".Then use the column as X-axis to create a column chart.
 4.png
Then use Switch() to sum values.

 

 

sum value =
SWITCH (
    SELECTEDVALUE ( 'for X-axis'[last period] ),
    "last 7", [last7],
    "last 28", [last28],
    "last 365", [last365]
)

 

 

My visualizations look like this:
 
5.png

 

Is the result what you want? If not, please upload some data samples and expected output.
Please do mask sensitive data before uploading.
 
Best Regards,
Eyelyn Qin
Anonymous
Not applicable
lbendlin
Super User
Super User

You need a table with this structure

 

IndexLabel
7L7
28L28
365L365

 

Mark the index column as whole number

Then you can add a measure to that table that based on the index computes the values you need.

Sort the Label column by the Index column.

Now you can add the Label to the legend, and the measure result to the values.

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.