Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

New Table from existing table using filters

Hi all,

 

I was looking for a solution in existing thread but I didn't find nothing.

 

I want to create a new table that take a distinct value from a column and then take cost considering the last period from another column

 

ResourceCost Period
abc10FEB 2021
cbd25DEC 2021
sad35DEC 2021
cds21FEB 2021
cbd25FEB 2021
sad15JAN 2022
sad50FEB 2022
abc13JAN 2022
   
   
   
   
Distinct resourceCostLast period
abc13JAN 2022
cbd25DEC 2021
sad50FEB 2022
cds21FEB 2021

 

I don't know if the better solution is:

-use Power Query

-use new table function in Power BI

 

I tried the last one but the code doesn't work....

 

Could you please help me? also linking a previously thread

 

Many thanks

1 ACCEPTED SOLUTION

Hi,

I think the reason is because there are some rows that shows the same information (duplicated rows).

If you want to keep the duplicated rows, please try the below.

Please check the below picture and the attached pbix file.

 

Picture3.png

 

New table Two = 
VAR lastperiod =
    GROUPBY (
        Data_Two,
        Data_Two[Resource],
        "@lastperiod", MAXX ( CURRENTGROUP (), Data_Two[Period] )
    )
VAR filterbylastperiod =
    CALCULATETABLE (
        Data_Two,
        TREATAS ( lastperiod, Data_Two[Resource], Data_Two[Period] )
    )
RETURN
    SUMMARIZE (
        SELECTCOLUMNS (
            filterbylastperiod,
            "Distinct resource", Data_Two[Resource],
            "Cost", Data_Two[Cost],
            "Last period", Data_Two[Period]
        ),
        [Distinct resource],
        [Cost],
        [Last period]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

GregVia_0-1647616832284.png

 

It works, but I don't understand why I have some resources that are duplicate or more...

Could you help also for this aspects?

 

Hi,

I think your use-case is different than what you described in your initial question.

Please share your sample pbix file.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Yes, i am an idiot.

 

in my data you can find this situation:

ResourceCost Period
abc10FEB 2021
cbd25DEC 2021
sad35DEC 2021
cds21FEB 2021
cbd25FEB 2021
sad15JAN 2022
sad50FEB 2022
abc13JAN 2022
sad50FEB 2022
cds21FEB 2021
abc13JAN 2022

 

there are more resources with the same cost and the same period.

 

Sorry again

 

 

Hi,

I think the reason is because there are some rows that shows the same information (duplicated rows).

If you want to keep the duplicated rows, please try the below.

Please check the below picture and the attached pbix file.

 

Picture3.png

 

New table Two = 
VAR lastperiod =
    GROUPBY (
        Data_Two,
        Data_Two[Resource],
        "@lastperiod", MAXX ( CURRENTGROUP (), Data_Two[Period] )
    )
VAR filterbylastperiod =
    CALCULATETABLE (
        Data_Two,
        TREATAS ( lastperiod, Data_Two[Resource], Data_Two[Period] )
    )
RETURN
    SUMMARIZE (
        SELECTCOLUMNS (
            filterbylastperiod,
            "Distinct resource", Data_Two[Resource],
            "Cost", Data_Two[Cost],
            "Last period", Data_Two[Period]
        ),
        [Distinct resource],
        [Cost],
        [Last period]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Jihwan_Kim
Super User
Super User

Hi,

One of the ways to solve this is to have the Period column as Date Type, and try to write the below to create a new table.

 

Please check the below picture and the attached pbix file.

 

Picture1.png

 

New table =
VAR lastperiod =
    GROUPBY (
        Data,
        Data[Resource],
        "@lastperiod", MAXX ( CURRENTGROUP (), Data[Period] )
    )
VAR filterbylastperiod =
    CALCULATETABLE ( Data, TREATAS ( lastperiod, Data[Resource], Data[Period] ) )
RETURN
    SELECTCOLUMNS (
        filterbylastperiod,
        "Distinct resource", Data[Resource],
        "Cost", Data[Cost ],
        "Last period", Data[Period]
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.