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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
CornelisV
Helper II
Helper II

Create new summarized table and skip blanks

Dear all,

 

I have a table with 3 columns:

TSPhase 1Phase2
01:00  
02:00Start 
03:00  
04:00  
05:00  
06:00 End
07:00 End
08:00 End
09:00  
10:00  

 

And the final output must be a new table, without discarding the table above:

TSPhase
02:00Start
06:00

End

 

Could you please demonstrate how to resolve?

 

Best regards,

 

Cornelis

2 ACCEPTED SOLUTIONS
v-xiaocliu-msft
Community Support
Community Support

Hi @CornelisV ,

 

In your example, if you only want to keep the first record where the value of the phase column is "end", please try this

Table 2 = 
var _startTime =MAXX( FILTER( 'Table',[Phase 1]="Start"),[TS])
var _endTime = CALCULATE(MIN('Table'[TS]),  FILTER('Table',[Phase2]="End"&&[TS]>=_startTime))
RETURN
     SELECTCOLUMNS(
        {
            (_startTime, "Start"),
            (_endTime, "End")
        },
        "Ts", [Value1],
        "Phase", [Value2]
    )

vxiaocliumsft_0-1731380145904.png

 

 

Best Regards,

Wearsky

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"TS"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Value"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Duplicates",{{"TS", type time}})
in
    #"Changed Type"

Hope this helps.

Ashish_Mathur_0-1731382198629.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"TS"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Value"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Duplicates",{{"TS", type time}})
in
    #"Changed Type"

Hope this helps.

Ashish_Mathur_0-1731382198629.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello @Ashish_Mathur ,

 

Thank you for your solution, the UnpivotOtherColums is doing the job and subsequently the distinct step.

 

Best regards,

 

Cornelis

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-xiaocliu-msft
Community Support
Community Support

Hi @CornelisV ,

 

In your example, if you only want to keep the first record where the value of the phase column is "end", please try this

Table 2 = 
var _startTime =MAXX( FILTER( 'Table',[Phase 1]="Start"),[TS])
var _endTime = CALCULATE(MIN('Table'[TS]),  FILTER('Table',[Phase2]="End"&&[TS]>=_startTime))
RETURN
     SELECTCOLUMNS(
        {
            (_startTime, "Start"),
            (_endTime, "End")
        },
        "Ts", [Value1],
        "Phase", [Value2]
    )

vxiaocliumsft_0-1731380145904.png

 

 

Best Regards,

Wearsky

Hello @v-xiaocliu-msft ,

 

Clearly a different approach. It works, thank you.

 

Best regards,

 

Cornelis

FreemanZ
Super User
Super User

hi @CornelisV ,

 

In Power Query, try like:

 

merge phase1 and phase2 columms

select the merged columm, remove blank and remove duplicate rows

Bibiano_Geraldo
Super User
Super User

HI @CornelisV ,

Create a new table in Power BI using the following DAX formula:

FinalTable = 
FILTER(
    UNION(
        SELECTCOLUMNS(
            FILTER(YourOriginalTable, NOT(ISBLANK(YourOriginalTable[Phase 1]))),
            "TS", YourOriginalTable[TS],
            "Phase", YourOriginalTable[Phase 1]
        ),
        SELECTCOLUMNS(
            FILTER(YourOriginalTable, NOT(ISBLANK(YourOriginalTable[Phase 2]))),
            "TS", YourOriginalTable[TS],
            "Phase", YourOriginalTable[Phase 2]
        )
    ),
    NOT(ISBLANK([Phase]))
)

 

Note: Make sure to change tables and columns names with your owns.
If this answer help you, please give a Kudo and mark as solution.

 

Thank you

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

Hi @Bibiano_Geraldo 

 

Thank you for your contribution, that looks promising.

I have checked your solution and this is what I get:

Remove double.png

I suppose that DISTINCT should be added. What is your opinion?

 

Best regards,

 

**bleep**

Hi, 
Adding DISTINCT can be a good idea if you want to ensure that your FinalTable does not contain duplicate rows. Here’s how you can modify your DAX formula to include DISTINCT:

 

FinalTable = 
DISTINCT(
    FILTER(
        UNION(
            SELECTCOLUMNS(
                FILTER(YourOriginalTable, NOT(ISBLANK(YourOriginalTable[Phase 1]))),
                "TS", YourOriginalTable[TS],
                "Phase", YourOriginalTable[Phase 1]
            ),
            SELECTCOLUMNS(
                FILTER(YourOriginalTable, NOT(ISBLANK(YourOriginalTable[Phase 2]))),
                "TS", YourOriginalTable[TS],
                "Phase", YourOriginalTable[Phase 2]
            )
        ),
        NOT(ISBLANK([Phase]))
    )
)

 

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

Hello @Bibiano_Geraldo ,

 

Yes, that is something what I have thought.:

 

Table = DISTINCT(FILTER(
    UNION(
        SELECTCOLUMNS(
            FILTER('Sheet1', NOT(ISBLANK('Sheet1'[Phase 1]))),
            "TS", 'Sheet1'[TS],
            "Phase", 'Sheet1'[Phase 1]
        ),
        SELECTCOLUMNS(
            FILTER('Sheet1', NOT(ISBLANK('Sheet1'[Phase2]))),
            "TS", 'Sheet1'[TS],
            "Phase", 'Sheet1'[Phase2]
        )
    ),
    (NOT(ISBLANK([Phase]))
)))
 
However, it does not remove multiple rows.
 
Best regards,
 
Cornelis
 
 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.