Forum Discussion

kentchiu's avatar
kentchiu
Regular Visitor
2 years ago
Solved

How to create a new table base on another table column with condition

Hi,   I am a new Power BI user and am having difficulty creating a table based on another table row with conditions.   What I would like to achieve is creating a new table with a distinct row of ...
  • xifeng_L's avatar
    2 years ago

    Hi kentchiu 

     

    You can try below DAX Table expression.

     

    New Table = 
    FILTER (
        Table,
        VAR CurCreated = Table[CREATED]
        VAR LatestCreated = CALCULATE (MAX(Table[CREATED]),ALLEXCEPT (Table,Table[ISSUE_KEY]))
        RETURN
        CurCreated = LatestCreated
    )

     

    But in your this case, the best method is use the PowerQuery to create the new table, which only need two step.

     

    Step1. Sort by ISSUE_KEY and CREATED (The CREATED need to sort in descending)

    Step2. Perform deduplication on on the table based on ISSUE_KEY

     

    Because the deduplication operation in PowerQuery will only retain the first occurrence of the row.

     

     

    Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

     

    Thank you~

     

  • sanalytics's avatar
    2 years ago

    Hello kentchiu 

     

    You can achieve this by using both DAX and PQ.
    Below is the DAX query

    VAR _1 =
    	ADDCOLUMNS(
    		SUMMARIZE(
    			Source,
    			Source[ISSUE_KEY],
    			Source[Issue Status Name]
    		),
    		"@Created",CALCULATE( MAX(Source[CREATED]) )
    	)
    	RETURN
    		_1

     

    PQ solution

    let
        Source = Source,
        #"Grouped Rows" = Table.Group(Source, {"ISSUE_KEY", "Issue Status Name"}, {{"Created", each List.Max([CREATED]), type nullable datetime}})
    in
        #"Grouped Rows"

     

    Below attached file

    https://we.tl/t-tJvge3FSTD 

     

    Let me know if it helps

    Regards,

    sanalytics

    If it is your solution then please like and accept it as solution