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
Delphia
Advocate II
Advocate II

Table with Totals by period

Hello everyone,

need your help with creating a table with totals like this:

Table_billable.jpg

I've created measures:

Bill ($) = SUM(Transactions[Bill])
last_w_b.jpg
last_4w_b.jpg
 
But if I create a matrix, I can use them only as Columns.
matrix.jpg
 
But I need a view like on the 1st image above. 
What is the best way to do it?
 
Thank you in advance for your help!
2 ACCEPTED SOLUTIONS
v-eqin-msft
Community Support
Community Support

Hi @Delphia ,

 

Based on my test, you could create a new table for period type like this( The index column is used to sort)

period type table.jpg

Then use the following formula to create a measure:

Measure =
SWITCH (
    MAX ( 'Period Type'[Period] ),
    "Last Week",
        CALCULATE (
            SUM ( 'Table'[Value] ),
            DATESINPERIOD ( 'Calendar'[Date], TODAY (), -7, DAY ),
            FILTER ( 'Table', 'Table'[Occupation] = MAX ( 'Table'[Occupation] ) )
        ),
    "Last 4 Weeks",
        CALCULATE (
            SUM ( 'Table'[Value] ),
            DATESINPERIOD ( 'Calendar'[Date], TODAY (), -28, DAY ),
            FILTER ( 'Table', 'Table'[Occupation] = MAX ( 'Table'[Occupation] ) )
        )
)

The final output is shown below:

sum by period.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-eqin-msft
Community Support
Community Support

Hi @Delphia ,

 

In my data sample, yes, creating a new table is not very necessary unless you want to filter data with slicer or some other conditions. But in this case, you need to create many measures.

 

 

Last Week = CALCULATE(SUM('Table'[Value]), DATESINPERIOD('Calendar'[Date],TODAY(),-7,DAY),FILTER('Table','Table'[Occupation]=MAX('Table'[Occupation])))
Last 4 Weeks = CALCULATE(SUM('Table'[Value]), DATESINPERIOD('Calendar'[Date],TODAY(),-28,DAY),FILTER('Table','Table'[Occupation]=MAX('Table'[Occupation])))

 

Measures.PNG

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-eqin-msft
Community Support
Community Support

Hi @Delphia ,

 

In my data sample, yes, creating a new table is not very necessary unless you want to filter data with slicer or some other conditions. But in this case, you need to create many measures.

 

 

Last Week = CALCULATE(SUM('Table'[Value]), DATESINPERIOD('Calendar'[Date],TODAY(),-7,DAY),FILTER('Table','Table'[Occupation]=MAX('Table'[Occupation])))
Last 4 Weeks = CALCULATE(SUM('Table'[Value]), DATESINPERIOD('Calendar'[Date],TODAY(),-28,DAY),FILTER('Table','Table'[Occupation]=MAX('Table'[Occupation])))

 

Measures.PNG

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much for your help!

v-eqin-msft
Community Support
Community Support

Hi @Delphia ,

 

Based on my test, you could create a new table for period type like this( The index column is used to sort)

period type table.jpg

Then use the following formula to create a measure:

Measure =
SWITCH (
    MAX ( 'Period Type'[Period] ),
    "Last Week",
        CALCULATE (
            SUM ( 'Table'[Value] ),
            DATESINPERIOD ( 'Calendar'[Date], TODAY (), -7, DAY ),
            FILTER ( 'Table', 'Table'[Occupation] = MAX ( 'Table'[Occupation] ) )
        ),
    "Last 4 Weeks",
        CALCULATE (
            SUM ( 'Table'[Value] ),
            DATESINPERIOD ( 'Calendar'[Date], TODAY (), -28, DAY ),
            FILTER ( 'Table', 'Table'[Occupation] = MAX ( 'Table'[Occupation] ) )
        )
)

The final output is shown below:

sum by period.PNG

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your help. It works with table. Nevertheless, I don't have a separate table with these values. I use measures in my calculations:

fields.jpg

 

For example:

Billable (hours) = SUM(Transactions[Billable_hours])
 
How do you think: is it possible to avoid creating a new table and use measures? If not, could you please suggest me what is the best way to create it?
Fowmy
Super User
Super User

@Delphia 

When you use a matrix visual, you have one option "Show on Rows" under Values section, you can turn it on and place the category in the columns to get the desired layout.


Fowmy_0-1622493106910.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you so much for your advice! But how can I make that in rows it will be description of value (hours, $, margin, etc) and on the columns time period (last month, last 4 months, last year, YTD, etc.)? Should I create another type of values? Or it should be another table (summerized?)?

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.