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

Create a measure that can calculate values based a slicer selection from a master table.

HI,

I have 2 tables,

Region master : 

Branch

Region

Delhi 1NR 1
LudhianaNR 1
ChandigarhNR 1
DehradunNR 1
Delhi 3NR 1
SonipatNR 1
Delhi 2NR 1
IndoreNR 2
RaipurNR 2
NoidaNR 2
GurgaonNR 2
AgraNR 2
LucknowNR 2
KolkataNR 2
RanchiNR 2

 

Budget

RegionBranch / AreaBudget
NR 1Chandigarh965
NR 1Dehradun686
NR 1Delhi 1620
NR 1Delhi 2289
NR 1Delhi 3968
NR 1Ludhiana820
NR 1Sonipat713
NR 1NR 1184
NR 2Agra280
NR 2Gurgaon219
NR 2Faridabad700
NR 2Indore697
NR 2Kolkata807
NR 2Lucknow512
NR 2Noida527
NR 2Raipur744
NR 2ROE 1488
NR 2ROE 2979
NR 2NR 2729
IndiaIndia162

 

I have two slicers based on region master branch & region.

 

I want 3 conditions that should work based on slicer selection and values that are fetched,

 

Condition 1: if no selection is made in the slicer : Value to be fetched and displayed Should be of "India" from Budget table,

COndition 2: If Region is selected in slicer  : Value to be fetched and displayed should be of "Selected REgion" from Budget table

Condition 3: If Branch is selected in slicer : Value to be fetched and displayed should be of "selected branch" from budget table.

 

 

Budget = var Region = SELECTEDVALUE('Region Master'[Region],"India")
var Branch = SELECTEDVALUE('Region Master'[Branch])
var calc = if(iscrossfiltered('BU 2022 (2)'[Branch / Area]),
            CALCULATE(SUM('BU 2022 (2)'[Bids Elev]),'BU 2022 (2)'[Branch / Area]=Region || 'BU 2022 (2)'[Branch / Area]=Branch),
            sum('BU 2022 (2)'[Bids Elev]))
var decimals = "0.00"
RETURN
    SWITCH ( TRUE(),
        calc > 1000000 , FORMAT ( calc / 1000 , decimals & "M" ),
        calc > 1000 , FORMAT ( calc / 1000 , decimals & "K" ),
        calc < 1000 , FORMAT(calc , decimals ),
        FORMAT ( calc , decimals )
    )

 

 

*The reason to add a region column in budget table is if in a region two branches are selected the sum should be displayed.

Kindly support.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ck1995 , try like

 

Budget = var Region = summarize(allselected('Region Master'), 'Region Master'[Region])
var Branch = summarize(allselected('Region Master'), 'Region Master'[Branch])
var calc = if(isfilter('Region Master'[Region]) || isfilter('Region Master'[Region]) ,
CALCULATE(SUM('BU 2022 (2)'[Bids Elev]),'BU 2022 (2)'[Region] in Region && 'BU 2022 (2)'[Branch / Area] in Branch),
CALCULATE(SUM('BU 2022 (2)'[Bids Elev]),'BU 2022 (2)'[Region] = "India"))
var decimals = "0.00"
RETURN
SWITCH ( TRUE(),
calc > 1000000 , FORMAT ( calc / 1000 , decimals & "M" ),
calc > 1000 , FORMAT ( calc / 1000 , decimals & "K" ),
calc < 1000 , FORMAT(calc , decimals ),
FORMAT ( calc , decimals )
)

View solution in original post

3 REPLIES 3
ck1995
Helper I
Helper I

@amitchandak I have a new development, as a Date table has been added a new slicer is created on the canvas. But budget does not have any relationship with date as budget is yearly so when the date slicer is selected, the values go blank. I tried using SUMX but the whole logic we created doesn't work. Also if i use the date slicer can we calculate (Budget / 12 )* (selected slicer month no).

amitchandak
Super User
Super User

@ck1995 , try like

 

Budget = var Region = summarize(allselected('Region Master'), 'Region Master'[Region])
var Branch = summarize(allselected('Region Master'), 'Region Master'[Branch])
var calc = if(isfilter('Region Master'[Region]) || isfilter('Region Master'[Region]) ,
CALCULATE(SUM('BU 2022 (2)'[Bids Elev]),'BU 2022 (2)'[Region] in Region && 'BU 2022 (2)'[Branch / Area] in Branch),
CALCULATE(SUM('BU 2022 (2)'[Bids Elev]),'BU 2022 (2)'[Region] = "India"))
var decimals = "0.00"
RETURN
SWITCH ( TRUE(),
calc > 1000000 , FORMAT ( calc / 1000 , decimals & "M" ),
calc > 1000 , FORMAT ( calc / 1000 , decimals & "K" ),
calc < 1000 , FORMAT(calc , decimals ),
FORMAT ( calc , decimals )
)

Thank you so much, Appreciate your help. It worked perfectly.

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.