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
AAMW01
Helper I
Helper I

Get individual values from table1 where table1 column = table 2 column then sum

I have this table:

Rows: Overhead Types

Columns: Fiscal Year

Values: Overhead Cost (from database)
Budget Values (from excel)

Each link to the calendar table. 

 

The values from the database are per row (transaction). 

The values from the excel are per month & based on Type like sales output, order input, overheads etc..)


My calculation to get that Budget values column is:

Overhead Budget Calc = CALCULATE(SUM('BudgetData21-22'[Value]), ALL('BudgetData21-22'[Value]), FILTER('BudgetData21-22', 'BudgetData21-22'[GroupType] = MAX('cwDashOverHeads-KPI10'[OverheadType])))
 
I have a filter on the visual that makes sure the budget "KPI" type is Overhead and then it makes sure that the "group" type (individual categories for each kpi type) is under the right kpi type.
 
Basically I am calculating the sum of the budget excel spreadsheet where the group type (text value equating to each overhead type) equals OverheadType in the database column.
Which gets  the right row values but Total value gets the last value in the rows.
 
Here is a screenshot of the table
AAMW01_0-1634209893511.png

As you can see it performs the calculation based on row correctly, however, gets the max value (last row's value) which I understand makes sense but I cannot figure out how to change it so I get the values in the rows where each group type is the same.

 

I have tried MAXX and SUMX but may not have been using them correctly in this case.

 

Any help greatly appreciated.

 

1 ACCEPTED SOLUTION
AAMW01
Helper I
Helper I

I have fixed my own issue. 

 

The problem was for some reason the query is using Max / Min from the string comparison cells and using that to calculate total value . Not sure why it does that because I used SUM (value) and my filter used MAX(group type) comparison.

 

I changed the first measure to this:

Overhead Budget Calc = 
CALCULATE(
    SUM('BudgetData21-22'[Value]), 
    FILTER('BudgetData21-22', 'BudgetData21-22'[GroupType] = SELECTEDVALUE('cwDashOverHeads-KPI10'[OverheadType]))
    )

 

This made the total blank which I then used an if else statement to do a conditional calculation.

 

total sum OH = 
IF(ISBLANK(CALCULATE('cwDashOverHeads-KPI10'[Overhead Budget Calc])), CALCULATE(SUM('BudgetData21-22'[Value])), [Overhead Budget Calc])

 

Works perfectly. 

 

Thanks to those who tried to help.

 

View solution in original post

11 REPLIES 11
AAMW01
Helper I
Helper I

I have fixed my own issue. 

 

The problem was for some reason the query is using Max / Min from the string comparison cells and using that to calculate total value . Not sure why it does that because I used SUM (value) and my filter used MAX(group type) comparison.

 

I changed the first measure to this:

Overhead Budget Calc = 
CALCULATE(
    SUM('BudgetData21-22'[Value]), 
    FILTER('BudgetData21-22', 'BudgetData21-22'[GroupType] = SELECTEDVALUE('cwDashOverHeads-KPI10'[OverheadType]))
    )

 

This made the total blank which I then used an if else statement to do a conditional calculation.

 

total sum OH = 
IF(ISBLANK(CALCULATE('cwDashOverHeads-KPI10'[Overhead Budget Calc])), CALCULATE(SUM('BudgetData21-22'[Value])), [Overhead Budget Calc])

 

Works perfectly. 

 

Thanks to those who tried to help.

 

Greg_Deckler
Super User
Super User

@AAMW01 This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

You will need to SUMX across a SUMMARIZE of your data just as you are summarizing the data in the visual, by Fiscal Year Comparison Type.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I have tried using SUMMARIZE but I assume I am not using it correctly.

 

My first query remains the same but this is my summarized query:

 

VAR __table = SUMMARIZE('BudgetData','BudgetData21-22'[GroupType],"__value", 'cwDashOverHeads-KPI10'[Overhead Budget Calc])
RETURN
IF(HASONEVALUE('BudgetData21-22'[GroupType]), 'cwDashOverHeads-KPI10'[Overhead Budget Calc], SUMX(__table,[__value]))

 

but I get similar results

AAMW01_0-1634309998674.png

 

Hi, @AAMW01 

 

You can try(use sumx and summarize() function):

measure =
SUMX (
    SUMMARIZE (
        BudgetData21 - 22,
        [Value],
        [GroupType],
        [Columns that need to be used in context],
        "a",
            CALCULATE (
                SUM ( 'BudgetData21-22'[Value] ),
                ALL ( 'BudgetData21-22'[Value] ),
                FILTER (
                    'BudgetData21-22',
                    'BudgetData21-22'[GroupType] = MAX ( 'cwDashOverHeads-KPI10'[OverheadType] )
                )
            )
    ),
    [a]
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

 

@v-janeyg-msft 

 

Thanks for the reply,

 

Unfortunately I get the same issue.

 

I don't know why the function is getting the MAX in value yet I am declaring SUM and filtering by a string's row value = max string value in a row (i.e. when both rows in each table each same group type).

 

I added the updated function you wrote however still get this result

 

AAMW01_0-1634739762502.png

 

As you can see it gets the latest rows value as the total and also leaves out tool rooms value.

 

Any ideas why?

 

Kind regards

Hello @AAMW01 

 

Any updates?

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If problem still persists, pls let me know.

 

Best Regards,

Community Support Team _ Janey

Hi, @AAMW01 

 

First of all, I don’t know what your data is. So I can only modify your existing measure. If your measure is correct, then the 'total' can be correct by the method of sumx(summarize()).

vjaneygmsft_0-1634780681651.pngvjaneygmsft_1-1634781260865.png

As for why total doesn't show sum but max value, this is also related to the measure you wrote, because the context of total is different from the context of the row with data on it. It can only be calculated based on the measure you write, total never only represents sum, it can represent any value as long as you want.

 

You can also judge whether the code is correct or not. You can copy the summrazie() code part in the form of new table in the desktop to check whether this virtual table meets your needs.

 

If you still can't get your desired result, Can you share some sample data and your desired result and your calculation logic? I will use my thoughts to rewrite the measure for you.😊

 

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.


Best Regards,

Community Support Team _ Janey

Hello, 

 

Thank you for the reply.

 

I have managed to get the totals somewhat correct however I still have the issue of the Overhead type "Tool Room" not showing up. 

Here is my measure:


budget total 2 = SUMX (
    SUMMARIZE (
        'BudgetData21-22',
        [GroupType],
       
        "a",
            CALCULATE (
                MAX ( 'BudgetData21-22'[Value] ),
                FILTER (
                    'cwDashOverHeads-KPI10',
                    'cwDashOverHeads-KPI10'[OverheadType] = MAX('BudgetData21-22'[GroupType])
                )
            )
    ),
    [a]
)

 

This gets 

AAMW01_0-1636710569953.png


I do not understand why it doesn't get the Tool Room value as the 2nd column row (using a similar query) gets the tool room value.

2nd column query is:

Overhead Budget Calc = CALCULATE(SUMX(FILTER('BudgetData21-22', 'BudgetData21-22'[GroupType] = MAX('cwDashOverHeads-KPI10'[OverheadType])), 'BudgetData21-22'[Value]))


However you can see it doesn't get the correct total like in the 4th column. 

Any help as to why I cannot get the tool room value in the 4th column using summarize & an inner query?

Thank you

@AAMW01 

 

If you can't share some sample data, I think it's hard to help you.

 

Best Regards,
Community Support Team _ Janey

I found that some cells were giving blank return values.

The code below fills in those values but it essentially uses the query from column 2 but again, the total doesn't match up. 

budget total 2 = SUMX (
    SUMMARIZE (
        'BudgetData21-22',
        [GroupType]
            
    ),
    IF(ISBLANK(CALCULATE (
                SUM ( 'BudgetData21-22'[Value] ),
                FILTER (
                    'cwDashOverHeads-KPI10',
                    'cwDashOverHeads-KPI10'[OverheadType] = 'BudgetData21-22'[GroupType]
                )
            )), CALCULATE(SUMX(FILTER('BudgetData21-22', 'BudgetData21-22'[GroupType] = MAX('cwDashOverHeads-KPI10'[OverheadType])), 'BudgetData21-22'[Value])),
             (CALCULATE (
                SUM ( 'BudgetData21-22'[Value] ),
                FILTER (
                    'cwDashOverHeads-KPI10',
                    'cwDashOverHeads-KPI10'[OverheadType] = 'BudgetData21-22'[GroupType]
                )
            )))
)

 

This gives 

AAMW01_1-1636716468259.png

 

If there is a way to just SUM column 2's measure I'd love that as I think its easier than column 4's measure.

Issue with column 2's measure: doesn't total correctly.
Issue with column 4's measure: has some blank cells for some reason but does total correctly.

Budget Table   
GroupTypeKPITypeFYDateValue
DomesticOHFY20-2101-Nov-201000
business developmentOHFY20-2101-Nov-20200
MarketingOHFY20-2101-Nov-202000
QualityOHFY20-2101-Nov-202000
FinancialOHFY20-2101-Nov-2011000
AdministrationOHFY20-2101-Nov-2030000
ITOHFY20-2101-Nov-2012000
DesignOHFY20-2101-Nov-2035000
Tool RoomOHFY20-2101-Nov-201000
SalesOHFY20-2101-Nov-2012000
ProductionOHFY20-2101-Nov-2012000
EngineeringOHFY20-2101-Nov-20-400
establishment costsOHFY20-2101-Nov-2030000

 

Overhead Table 
AccIDGoodsValueTransactionDateOverheadType
30000.501/11/2020Domestic
30002502/11/2020business development
30001103/11/2020Marketing
30001.0404/11/2020Quality
30000.5205/11/2020Financial
25001.9906/11/2020Administration
25002.407/11/2020IT
25005.308/11/2020Design
25002109/11/2020Tool Room
21001510/11/2020Sales
21001911/11/2020Production
210011.1412/11/2020Engineering
21004.713/11/2020establishment costs

 

So the overhead table is based on transactions and the budget table is based on overhead totals for a time period.

 

Both tables link to a calendar table which is not an issue.

 

The visual uses the Overhead type as a row, fiscal year comparison as a column (which is connected to the calendar table), Budget column which uses the measure above (which doesnt use the summarize function but gives tool room's value), the variance is just a column - column function and the budget total 2 column is the measure shown above (using the summarize, but doesn't give the Tool Room value)

Calendar Table is 

Calendar Table = ADDCOLUMNS(
    CALENDAR(DATE(2003,01,01), DATE(2025,01,01)),
    "Year", YEAR([Date]),
    "Month Year Num", CONCATENATE(YEAR([Date]), FORMAT([Date],"MMM")),
    "Month Num", MONTH([Date]),
    "Month", FORMAT([Date], "MMM"),
    "Quarter Num", FORMAT([Date], "Q"),
    "Quarter", CONCATENATE("Q", FORMAT([Date], "Q")),
    "DAY", FORMAT([Date], "D"),
    "Week", FORMAT([Date], "WW")
    
    )


and FY columns are 

FiscalYearNumber = If( Month([Date]) >= 6  , Year([Date]),Year([Date]) -1 )
FiscalYearDisplay = "FY"&Right(Format([FiscalYearNumber],"0#"),2)&"-"&Right(Format([FiscalYearNumber]+1,"0#"),2)



 

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.