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
luisClive
Helper III
Helper III

Calculate for sub region ( allocate sales budget)

Hi All

 

Can you help with following?

 

I have the following  main table

Sales  
MonthOUSales
JanAsia204
JanEurope234
JanPacific211
FebAsia456
FebEurope233
FebPacific123
MarchAsia345
MarchEurope321
MarchPacific179

 

and a sub table ( wherein asia in broken into 3 parts by %)

Sub Region(Main region is Asia)
South East Asia40%
ME35%
North25%

 

I want a sales measure for sub region ( or calculated column if its a better approach)

 

the solution shold be like

 

Sales  
MonthOUSolution
JanSouth East Asia40% of  204
JanME35% of  204
JanNorth25% of  204
FebSouth East Asia 
FebME 
FebNorth 
MarchSouth East Asia 
MarchME 
MarchNorth 

 

 

of course these are samples, actual table are quite big

1 ACCEPTED SOLUTION

Hi, @luisClive 

 

You may modify the measure as below. The pbix file is attached in the end.

Result = 
var tab = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT(Sales[Month]),
        DISTINCT(Sub[Sub Region])
    ),
    "Result",
    var month = [Month]
    var subregion = [Sub Region]
    var s = 
    CALCULATE(
            SUM(Sales[Sales]),
            FILTER(
                ALL(Sales),
                [Month]=month&&
                [OU]="Asia"
            )
    )
    var v = LOOKUPVALUE(Sub[(Main region is Asia)],Sub[Sub Region],subregion)
    return
    s*v
)

return
SUMX(
    tab,
    [Result]
)

 

Result:

a.png

 

Best Regards

Allan

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

View solution in original post

6 REPLIES 6
v-alq-msft
Community Support
Community Support

Hi, @luisClive 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Sales:

f1.png

 

Sub:

f2.png

 

You may create a measure as below.

Result = 
var s = 
CALCULATE(
        SUM(Sales[Sales]),
        FILTER(
            ALL(Sales),
            [Month]=MAX(Sales[Month])&&
            [OU]="Asia"
        )
)
var v = LOOKUPVALUE(Sub[(Main region is Asia)],Sub[Sub Region],MAX(Sub[Sub Region]))

return
s*v

 

Result:

f3.png

 

Best Regards

Allan

 

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

@v-alq-msft 

 

many many thanks

 

How do i adjust the formula to return grand total instead of just max?

 

 

luisClive_0-1605960604816.png

 

Hi, @luisClive 

 

You may modify the measure as below. The pbix file is attached in the end.

Result = 
var tab = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT(Sales[Month]),
        DISTINCT(Sub[Sub Region])
    ),
    "Result",
    var month = [Month]
    var subregion = [Sub Region]
    var s = 
    CALCULATE(
            SUM(Sales[Sales]),
            FILTER(
                ALL(Sales),
                [Month]=month&&
                [OU]="Asia"
            )
    )
    var v = LOOKUPVALUE(Sub[(Main region is Asia)],Sub[Sub Region],subregion)
    return
    s*v
)

return
SUMX(
    tab,
    [Result]
)

 

Result:

a.png

 

Best Regards

Allan

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

Many thanks for help

amitchandak
Super User
Super User

@luisClive , Create a new table like.

filter(crossjoin(sales,sub),sales[OU] =sub[region])

crossjoin need all columns to different across table, so if they are same you can rename usinf select columns

refer

https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

 

@amitchandak 

 

did not work for me

 

this part is not clear

sales[OU] =sub[region])

 

Not working because of no unique values on both tables?

 

all columns are different for me

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.