Forum Discussion

Tobz007's avatar
Tobz007
Frequent Visitor
1 year ago
Solved

How to Create A Dynamic List from a String Column

I have a table (lets call it "Table") that contains "Names", "Date" and other info for the Names, every month a new list is appended to the Table to show the names and updated information, sometimes the appended table contains same name from last month, sometimes it contains some new names and sometimes some names from previous month is removed, how do I create power query steps (or DAX) that;
1. Creates a list which comprises of the names from the previous month in the Table.
2. Based on the list, if a name from the previous month list no longer exist in current month, it returns A, if name that does not exist in previous month is added in current month it returns B, else C.

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Tobz007 ,

     

    Thanks to mickey64  and ryan_mayu  for their quick replies. I have a DAX method to add:

    (1) This is my table. It contains data for this month and last month.

     

    (2) We can create a [Previous month] table.

    Previous month = 
    var _month=MONTH(MAXX(ALL('Table'),[Date]))-1
    RETURN CALCULATETABLE(VALUES('Table'[Name]),FILTER('Table',MONTH([Date])=_month))

    (3) We can create a table and a status column.

    Table 2 = VALUES('Table'[Name])
    Status = 
    var _month=MONTH(MAXX(ALL('Table'),[Date]))
    var _table= CALCULATETABLE(VALUES('Table'[Name]),FILTER('Table',MONTH([Date])=_month))
    var _table_a=EXCEPT('Previous month',_table)
    var _table_b=EXCEPT(_table,'Previous month')
    RETURN SWITCH(TRUE(),
    [Name] in _table_a,"A",
    [Name] in _table_b,"B",
    "C")

     

    Best Regards,

    Neeko Tang

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

5 Replies

  • could you pls provide some sample data and expected output?

  • Step 0: I use these data.

    "PreviousMonth" Table

     

    "ThisMonth" Table

     

    Step 1: I do "Merge Queries as New" to "PreviousMonth" Table on Power Query Editor.

     

     

    Step 2: I add a "Conditional" column below.

     

     

    Step 3: I remove the "ThisMonth.Names" column and change a type of "Custom" column to "Text".

     

    Step 4: I do same procedure to "ThisMonth" Table.

     

    Step 5: I do "Append Queries as New" to the "Merge1" Table and the "Merge2" Table.

     

    Step 6: I remove duplicates.

     

    Step 6: I make a table.

     

    • Tobz007's avatar
      Tobz007
      Frequent Visitor

      Thanks alot mickey64, really appreciate the reply.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Tobz007 ,

     

    Thanks to mickey64  and ryan_mayu  for their quick replies. I have a DAX method to add:

    (1) This is my table. It contains data for this month and last month.

     

    (2) We can create a [Previous month] table.

    Previous month = 
    var _month=MONTH(MAXX(ALL('Table'),[Date]))-1
    RETURN CALCULATETABLE(VALUES('Table'[Name]),FILTER('Table',MONTH([Date])=_month))

    (3) We can create a table and a status column.

    Table 2 = VALUES('Table'[Name])
    Status = 
    var _month=MONTH(MAXX(ALL('Table'),[Date]))
    var _table= CALCULATETABLE(VALUES('Table'[Name]),FILTER('Table',MONTH([Date])=_month))
    var _table_a=EXCEPT('Previous month',_table)
    var _table_b=EXCEPT(_table,'Previous month')
    RETURN SWITCH(TRUE(),
    [Name] in _table_a,"A",
    [Name] in _table_b,"B",
    "C")

     

    Best Regards,

    Neeko Tang

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

    • Tobz007's avatar
      Tobz007
      Frequent Visitor

      Thanks alot v-tangjie-msft, I did found a way around the solution using power query, but your feedback is quite helpful! Thanks again.