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
fleetingImage
New Member

Create a new table using an existing table with distinct values and substrings

Hi,

 

I have a fact table that looks like this:

 

fact_sales:

ComparativeRegionCountryProductMonthSales
2020 PlanAPACThailandt-shirts1 $           10.00
2020 PlanAPACThailandshorts1 $           20.00
2020 PlanAPACThailandsnickers1 $           34.00
2020 PlanAPACThailandballs1 $           20.00

 

I'm importing this table from an Excel file.  Using this data I want to create a new table to use as a dimension (from column "Comparative").  So the new dim table will look like this:

 

dim_comparative:

ComparativecompYearcompActual
2020 Plan20201
2020 Forecast20201
2020 Actual20201
2019 $c20190
2018 $c20180

 

The "Comparative" column holds the distinct values from the fact table.  the "compYear" columns holds the first 4 characters from Comparative, and "compActual" shows a 1 when compYear is the current year, and 0 otherwise.

 

I've been investigating different alternatives like GENERATE(), DISTINCT() and such, but I wasn't able to figure out how to do this.  Also, the new table should be derived from the already loaded table or I should import the data from Excel twice, one for the fact and one for transforming the data into the dim table?

 

Thanks for your help! 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@fleetingImage ,Try like

selectcolumns(distinct(table[Comparative]), "Comparative",[Comparative],"compYear", left([Comparative],4), "compActual", if(left([Comparative],4) =year(today())))

 

or

 

distinct(selectcolumns(Table, "Comparative",[Comparative],"compYear", left([Comparative],4), "compActual", if(left([Comparative],4) =year(today()))))

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@fleetingImage ,Try like

selectcolumns(distinct(table[Comparative]), "Comparative",[Comparative],"compYear", left([Comparative],4), "compActual", if(left([Comparative],4) =year(today())))

 

or

 

distinct(selectcolumns(Table, "Comparative",[Comparative],"compYear", left([Comparative],4), "compActual", if(left([Comparative],4) =year(today()))))

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.