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
rajbi2020
Frequent Visitor

Need help to sum depending on mutliple conditons.

Hi All, I need some help .. 

 

I have 3 tables where one is BILLING ,users list and team ,currentteam. with Employe and current dept .I wanted to calculate the sum for each YTD for EMPLOYEE ,by team . 

 

1 Senario 

 if employee never change the team get sum (amt)  irrrespective of the dept .

2. 

 If employee changed the teams from 11 to 22  and  we select 22 which is currect team . then only display his current dept sum(amt) ie BBC 20 and If we select 11 then  display sum(other amount) ie leave his current team dept amout . Ie 

 sum(amount) not inclusive of DEPT BBC

 

I am trying to create a measure for this . using calculate and filters .. but i am not sucessfull

Actual = CALCULATE(SUM(Billed[AMOUNT]),FILTER(Employeeytd ,Employeeytd[DEPT]=FIRSTNONBLANK(CurrentUser[DEPT],TRUE())))

 

1  Billing table

EMPLOYEEperiod(year&month)DeptAmount
1201912ABC10
1202001ABC12
1202002BBC14
2201912ABC10
2202001ABC12
2202002DBF14
2202003BBC20
3201912CDE19
2202001BBC10

 

 

 2 Employee ytd TABLE

EMPLOYEEperiod(year&month)team
120191211
120200111
120200211
120200311
220191211
220200122
220200222
320191244

 

3 .Current user table latest month.

employeedept
1ABC
2BBC
3ABC
  
5 REPLIES 5
smarthp29
Helper I
Helper I

You would require 1 calculated column to tag the latest department in the billing table and based on that you can create your measure.

 

Lastest Dept Tagging = IF(Billing[Dept] = CALCULATE(MAX(CurrentUser[Dept]),ALLEXCEPT(CurrentUser,CurrentUser[Employee])),TRUE(),FALSE())
 
Total Amount = IF(DISTINCTCOUNTNOBLANK(EmployeeYTD[Team])>1,CALCULATE(SUM(Billing[Amount]),Billing[Lastest Dept Tagging]=TRUE()),SUM(Billing[Amount]))
 
Output Table
image.png

 

 

 

 

 

 
EmployeeYTD Table
image.png
 
 
 
 
 
 
 
 
Billing Table
 

image.png

 

 

 

 

 

 

 

 

 

CurrentUser Table

image.png

 

The first cust column help to define current dept .. if true or false

 

then there is a realtionship between teammaster and EmployeeYTD ,So when i select team 1 from the slicer then the count is always 1 for that team .. .. . 

 

TEAM IDDEPT
1ABC
2BBC

 

So I tried something like below .. .. and got the current dept amount correctly .. but when i selected the second team I should get the remaining amount ..Since the first  count condition is satisfied its is not going to else if i select the old team.

CALCULATE(DISTINCTCOUNT(EmployeeYTD[team]),CROSSFILTER(DEPT[TEAM_ID],EmployeeYTD[team],None)) 
 
Since i set used crossfilter none its get me all the user list which is again wrong.. I am not sure if I can use cross filter or something else 
 
please suggest

@rajbi2020 

 

I am unable to understand your full requirements. Let me know what output are you expecting. TeamID comes from TeamMaster Table.

Attached screenshot of the output i get based on my TeamID Slicer.

image.png

 

If the employe doesnt change the team then we should get the total amount ignoring the dept he worked . 

 

So for employee 1 amount is 36 -team 1

So for employee 2 - If we select team 1 (old team) then we need to get the sum(all dept except BBC which is current)

     if we select team 2 then we need to get only amount related to BBC ie 30 ) below are the table output 

 

Sorry for confusing .            

 

EMPLOYEEAmount
136
236 (EXCEPT BBC DEPT)

 

If selected 22 

EmployeeAmount
230(only BBC)

I will try now thanks .

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.