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
Sir_Rosenfeld
New Member

Table showing column as percentage of another column

Hi,

 

I have a table that looks like this

|          Date             |   Total  |   Loss  |
|---------------------|---------|--------|
|      Jan 1 2018       |    90      |    5     |
|---------------------|---------|--------|
|     Jan 3 2018         |    10     |    5      |
|---------------------|---------|--------|
|      Feb 1 2018       |    50     |      5    |
|---------------------|---------|--------|
|      Feb 3 2018       |    50     |    10    |
|---------------------|---------|--------|

I wanna be able to show in a table how much percentage of "Total" "Loss" is depending on the period.

For example if in my dashboard I show the table visualizer as months, it should give :

|        Date        |  Loss % |
|----------------|----------|
|    Jan 2018     |   10%     |
|----------------|----------|
|    Feb 2018     |   15%    |
|----------------|----------|

But if I show it as year, it should give :

|    Date   | Loss % |
|----------|---------|
|   2018   |  12.5%  |
|----------|---------|

 

Right now the only solution I have found is to create tables in the Data tab that would sum up my main table for each Month. But that can't be a permanent solution to me (I end up with too many tables, as I have to do that kind of table for many different columns and conflicting relationships). Maybe a custom visualizer? Any alternative solution?

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

Hi Sir_Rosenfeld,

 

So you need column date in the first column of new table to be dynamic based on something you selected, right? If that's your requirement, I'm afraid neither dynamic calculate table nor dynamic calculate column is supported in power bi. However, as a workaround, you can create new tables using dax formula below:

Table =
SUMMARIZE (
    Table1,
    Table1[Date].[Year],
    Table1[Date].[Month],
    "Date", LEFT ( Table1[Date].[Month], 3 ) & " "
        & Table1[Date].[Year],
    "Loss%", SUM ( Table1[Loss] ) / SUM ( Table1[Total] )
)

 

1.PNG  

 

Table 2 =
SUMMARIZE (
    'Table1',
    Table1[Date].[Year],
    "Date", Table1[Date].[Year],
    "Loss%", SUM ( Table1[Loss] ) / SUM ( Table1[Total] )
)

2.PNG  

 

In addtion, if you don't want the first column to be dynamic, I would recommend you to create an addtional table selection and then create a measure like pattern below:

 

Loss% = 
IF (
    SELECTEDVALUE ( Selection[Selection] ) = "Year",
    CALCULATE (
        SUM ( Table1[Loss] ) / SUM ( Table1[Total] ),
        ALLEXCEPT ( Table1, Table1[Date].[Year] )
    ),
    IF (
        SELECTEDVALUE ( Selection[Selection] ) = "Year&Month",
        SUMX(ALLEXCEPT(Table1, Table1[Date].[Year], Table1[Date].[Month]), Table1[Loss] / SUMX(ALLEXCEPT(Table1, Table1[Date].[Year], Table1[Date].[Month]), Table1[Total]))
    )
)

 

Regards,

Jimmy Tao

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

 

Create a Calendar Table and build a relationship from the Date column of the Data Table to the Date column of the Calendar Table.  In the Calendar Table, create 2 additional columns for Month and Year

 

Month=FORMAT(Calendar[Date],"mmmm")

Year=Year(Calendar[Date])

 

In the visual, drag Year and/or Month to your visual (from the Calendar Table).  Write these measures:

 

=SUM(Data[Loss])/SUM(Data[Total])

 

Format this as %.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yuta-msft
Community Support
Community Support

Hi Sir_Rosenfeld,

 

So you need column date in the first column of new table to be dynamic based on something you selected, right? If that's your requirement, I'm afraid neither dynamic calculate table nor dynamic calculate column is supported in power bi. However, as a workaround, you can create new tables using dax formula below:

Table =
SUMMARIZE (
    Table1,
    Table1[Date].[Year],
    Table1[Date].[Month],
    "Date", LEFT ( Table1[Date].[Month], 3 ) & " "
        & Table1[Date].[Year],
    "Loss%", SUM ( Table1[Loss] ) / SUM ( Table1[Total] )
)

 

1.PNG  

 

Table 2 =
SUMMARIZE (
    'Table1',
    Table1[Date].[Year],
    "Date", Table1[Date].[Year],
    "Loss%", SUM ( Table1[Loss] ) / SUM ( Table1[Total] )
)

2.PNG  

 

In addtion, if you don't want the first column to be dynamic, I would recommend you to create an addtional table selection and then create a measure like pattern below:

 

Loss% = 
IF (
    SELECTEDVALUE ( Selection[Selection] ) = "Year",
    CALCULATE (
        SUM ( Table1[Loss] ) / SUM ( Table1[Total] ),
        ALLEXCEPT ( Table1, Table1[Date].[Year] )
    ),
    IF (
        SELECTEDVALUE ( Selection[Selection] ) = "Year&Month",
        SUMX(ALLEXCEPT(Table1, Table1[Date].[Year], Table1[Date].[Month]), Table1[Loss] / SUMX(ALLEXCEPT(Table1, Table1[Date].[Year], Table1[Date].[Month]), Table1[Total]))
    )
)

 

Regards,

Jimmy Tao

SivaMani
Resident Rockstar
Resident Rockstar

@Sir_Rosenfeld,

 

What is the datatype of Date field? or Do you have any field with Date datatype?

 

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.