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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mdobrescu
New Member

Parse data before import to dataset

Hello,

 

I have a CSV file hosted on OneDrive Bussines which is linked to a PowerBi dataset. 

Lets say both the CSV file and Powerbi dataset have 3 columns(column1, column2, column3).

But sometimes the CSV file after an export has only 2 columns(column1,column3). Because the column2 is missing from the CSV, on PowerBi dataset refresh, I'll get an error saying that column2 is missing. 

 

So the questions is, if it is possible to parse the values before the imports similar to this:

if (CSV.column2 is null) ? {Dataset.column2.value = null) : {Dataset.column2.value = CSV.column2.value)

 

Thank you,

Mihai

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @mdobrescu,

According to your description, I'd like to suggest you can add a custom query step with an if statement to check the data source fields. Then use the current result or try to use add column function to add these missed columns.

Table.ColumnCount - PowerQuery M | Microsoft Docs

Table.AddColumn - PowerQuery M | Microsoft Docs

    Source = xxxxxx,
    Custom=
        if Table.ColumnCount(Source) > 2 then
            Source
        else
            Table.AddColumn(
                Source,
                "column2",
                each null
            )
in
    Custom

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @mdobrescu,

According to your description, I'd like to suggest you can add a custom query step with an if statement to check the data source fields. Then use the current result or try to use add column function to add these missed columns.

Table.ColumnCount - PowerQuery M | Microsoft Docs

Table.AddColumn - PowerQuery M | Microsoft Docs

    Source = xxxxxx,
    Custom=
        if Table.ColumnCount(Source) > 2 then
            Source
        else
            Table.AddColumn(
                Source,
                "column2",
                each null
            )
in
    Custom

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
lbendlin
Super User
Super User

yes, that is possible.  Change the query to remove the reference to the expected number of columns, and then use try ... otyherwise ...  in Power Query to handle your scenarios.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.