Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Need help in applying filters and getting multiple column data with respect to ID

Hello All,

 

I am new Power BI and not getting how to apply filter in below condition.

kindly help me on this issue.

I am having Excel data like,

 

DateEmployeeIDSickLeavesPaidLeavesHolidaysUnpaidLeaves
201905011993037Not Well---
201905021993037----
201905031993037-Saturday--
201905041993037-Sunday--
201905051993037----
201905061993037Not Well---
201905071993037----
201905081993037--Holiday-
201905091993037----
201905101993037---For Personal Reason
201905012001234Not Well---
201905022001234Not Well---
201905032001234----
201905042001234-Saturday--
201905052001234-Sunday--
201905062001234----
201905072001234----
201905082001234--Holiday-
201905092001234----
201905102001234----
201905012345654---For Personal Reason
201905022345654----
201905032345654----
201905042345654-Saturday--
201905052345654-Sunday--
201905062345654Not Well---
201905072345654----
201905082345654--Holiday-
201905092345654----
201905102345654----

 

I am trying create a Calculated Column or Measure to achieve folowing result and i am trying to show in Table view like below,

From above Excel data i am trying to display Three columns in Power BI Table as below. But i am not getting how to apply filter so that it will display only Leave date of Employee with ID, Date and Reason. Like this my Excel contains many Employees data for many years.  

LeaveDateEmployeeIDLeaveReason
201905011993037Not Well
201905031993037Saturday
201905041993037Sunday
201905061993037Not Well
201905081993037Holiday
201905101993037For Personal Reason
201905012001234Not Well
201905022001234Not Well
201905042001234Saturday
201905052001234Sunday
201905082001234Holiday
201905012345654For Personal Reason
201905042345654Saturday
201905052345654Sunday
201905062345654Not Well
201905082345654Holiday

 

Kindly help me on this issue.

Thanks in advance!!

 

Regards,

Amar

  • Refer the new column in table in the attached file after signature

     

    Column = SWITCH(TRUE(),Sheet1[SickLeaves]<>"-",[SickLeaves],[PaidLeaves]<>"-",[PaidLeaves],[Holidays]<>"-",[Holidays],[UnpaidLeaves]<>"-",[UnpaidLeaves],"No Leave")

     

6 Replies

  • Anonymous 

    If they are blank the

    coalesce(table[SickLeaves],table[PaidLeaves],table[Holidays],table[UnpaidLeaves])

    Or try like

    switch(true(),
    table[SickLeaves]<>"-",table[SickLeaves],
    table[PaidLeaves]<>"-",table[PaidLeaves],
    table[Holidays]<>"-",table[Holidays],
    table[UnpaidLeaves]<>"-",table[UnpaidLeaves],
    "Other"
    )

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak 

      Hello Amit,

       

      Thank you so much for your quick response.

      I tried creating Calculated column with Switch as above but it not showing as i wanted show. If Employee has not taken any Leave then in the List that Employee should not be listed.

      And i am trying to display Date, EmployeeID and LeaveReason if there is Leave for that Employee then only it should display otherwise not. For all employees Saturday and Sunday and Holidays are compulsory to display. So what i am trying here is just filter Leaves column and if any leaves are there then display it Date, EmployeeID and Reason.

      By using above switch solution it is displaying only others i.e. false condition for all Employees.

      And instead of "-" Excel is having "Blanks".

       

      And i tried with "COALESCE" and it showing reasons. But for this i have created Calculated Column and i have added all Leaves Columns in it.

      And in Table i have dragged Date , EmployeeID and And this newly created CAlculated column. It shows all Employees Data with Blanks also. But i trying to show only Leaves Data only.

       

       

      I am trying with applying filters but it is not working. Kindly help!

       

      Regards,

      Amar

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        Refer the new column in table in the attached file after signature

         

        Column = SWITCH(TRUE(),Sheet1[SickLeaves]<>"-",[SickLeaves],[PaidLeaves]<>"-",[PaidLeaves],[Holidays]<>"-",[Holidays],[UnpaidLeaves]<>"-",[UnpaidLeaves],"No Leave")

         

  • Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", Int64.Type}, {"EmployeeID", Int64.Type}, {"SickLeaves", type text}, {"PaidLeaves", type text}, {"Holidays", type text}, {"UnpaidLeaves", type text}}),
        #"Replaced Value" = Table.ReplaceValue(#"Changed Type","-",null,Replacer.ReplaceValue,{"SickLeaves", "PaidLeaves", "Holidays", "UnpaidLeaves"}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Date", "EmployeeID"}, "Attribute", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
    in
        #"Removed Columns"

    Hope this helps.