Forum Discussion

rajbi2020's avatar
rajbi2020
Frequent Visitor
6 years ago

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

  • 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

     

     

     

     

     

     
    EmployeeYTD Table
     
     
     
     
     
     
     
     
    Billing Table
     

     

     

     

     

     

     

     

     

     

    CurrentUser Table

     

    • rajbi2020's avatar
      rajbi2020
      Frequent Visitor

      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
      • smarthp29's avatar
        smarthp29
        Icon for Helper I rankHelper I

        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.