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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Corlin
Frequent Visitor

Field mismatch when using UNION

I am trying to combine two tables, but when I try to union them I get a mismatch between the fields as seen below.
The goal is to create a table that contains all dates and filling the empty fields with zeroes.

The calendar contains "dates"
WFOpenClosed contains "dates", "Open", "Closed", "WorkflowID"

I have been trying to follow this implementation.
Any help with my problem would be greatly appreciated.

I am using the following code to populate the table:

WFOpenClosedZeroFilled = 
UNION (
    WFOpenClosed;
    ADDCOLUMNS (
        EXCEPT ( VALUES ( 'calendar'[Date] ); VALUES ( WFOpenClosed[Date] ) );
        "Open"; 0;
        "Closed"; 0;
        "WorkflowID"; 0
    )
)


Closed and Date is swapped in the union.

 

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Corlin

 

You may have a look at UNION Function. To get the table as requested, the first way is to make sure the 'Date' column in WFOpenClosed table is the first column as below. Then you may get the table with your code.

1.png

 

The second way is to change the code like below to get the table as requested.

WFOpenClosedZeroFilled =
UNION (
    SELECTCOLUMNS (
        WFOpenClosed,
        "date", WFOpenClosed[date],
        "Closed", WFOpenClosed[Closed],
        "WorkflowID", WFOpenClosed[WorkflowID],
        "Open", WFOpenClosed[Open]
    ),
    ADDCOLUMNS (
        EXCEPT ( VALUES ( 'calendar'[Date] ), VALUES ( WFOpenClosed[Date] ) ),
        "Closed", 0,
        "Open", 0,
        "WorkflowID", 0
    )
)

Regards,

Cherie

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-cherch-msft
Employee
Employee

Hi @Corlin

 

You may have a look at UNION Function. To get the table as requested, the first way is to make sure the 'Date' column in WFOpenClosed table is the first column as below. Then you may get the table with your code.

1.png

 

The second way is to change the code like below to get the table as requested.

WFOpenClosedZeroFilled =
UNION (
    SELECTCOLUMNS (
        WFOpenClosed,
        "date", WFOpenClosed[date],
        "Closed", WFOpenClosed[Closed],
        "WorkflowID", WFOpenClosed[WorkflowID],
        "Open", WFOpenClosed[Open]
    ),
    ADDCOLUMNS (
        EXCEPT ( VALUES ( 'calendar'[Date] ), VALUES ( WFOpenClosed[Date] ) ),
        "Closed", 0,
        "Open", 0,
        "WorkflowID", 0
    )
)

Regards,

Cherie

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your input, I ended up using the SELECTCOLUMN to solve my problem.

PattemManohar
Community Champion
Community Champion

@Corlin Please post the sample input data and your expected output as well, which will be helpful to understand and resolve your issue quickly.....





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




My input data is the bottom half of the image.
The value seen in the Date column in the bottom half is decimal number corresponding to a date, and as you can see are the upper half of the rows inputted wrong as the date gets in the Closed column and the Closed value in the Date column

What I want to achieve is inserting 0 for the closed, open and WorkflowID for the days nothing were logged as seen below.



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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