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
FredericoMM
Helper I
Helper I

New column witth conditions from two tables

Hi all,

 

I have two tables: Calendar and CountriesHolidays:

cal.pnghol.png

I have to combine them to in order to create a new column in the Calendar table where I must assign a '0' when it's a Holiday in Portugal and Brazil. I've tried different solutions, but nothing seems to result. Joining tables through PowerQuery isn't possible cause I do not have access to the source files.

 

Any ideas? Thanks very much

 

1 ACCEPTED SOLUTION

Hi @FredericoMM ,

 

The issue was that in my test file I did not had repeated values in the dates for holidays now it works properly:

 

Use the formula below:

Is Holiday = 
IF (
    COUNTROWS (
        FILTER (
            CountriesHolidays;
            CountriesHolidays[ds_holidays] = 'Calendar'[Date]
                && CountriesHolidays[Is_country] = 1
        )
    ) >= 1;
    1;
    0
)

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

10 REPLIES 10
MFelix
Super User
Super User

Hi Frederico,

 

Add the following colums to your data:

 

Table Holidays new column:

 

Is_country = IF('Table'[Country] in {"Portugal"; "Brazil"};1 ; 0)

 

Table Calendar new column:

 

Is Holiday = 
LOOKUPVALUE('Table'[Holiday];'Table'[Date];'calendar'[Date];'Table'[Is_country];1)

Or a value with 1 

Is Holiday = 
LOOKUPVALUE('Table'[Is_country];'Table'[Date];'calendar'[Date];'Table'[Is_country];1)

 

then  you can filter out on your measure the columns is holiday = 1

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi, @MFelix 

Thank you for your fast solution.

Unfortunately, the second part of it isn't working properly... It shows 1 and 0 randomly, apparently.

holiday.png

 

Basically I need that column 'Alocação', to show '0' instead of '8' when whether it is a holiday in PT and BR:

Thanks in advance! 

Hi @FredericoMM ,

 

The last parameter on your formula is missing so it's not searching for the countries that are marked in the holiddays table you have:

 

 

Is Holiday = 
LOOKUPVALUE(CountriesHolidays[Is_country];CountriesHolidays[ds_holidays];'calendar'[Date].Date;1)

 

The formula must be:

 

Is Holiday = 
LOOKUPVALUE(CountriesHolidays[Is_country],CountriesHolidays[ds_holidays],'calendar'[Date].Date,CountriesHolidays[Is_country],1)

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks, @MFelix 

When I paste the formula to create a new column and then I filter for '1' , it just seems to have 3 rows:

FredericoMM_0-1598440853376.png

This is not correct...

Hi @FredericoMM ,

 

Is your formula on the holidays table giving you the correct values for the dates that are in Portugal and Brazil?

 

The column you are creating is on the Calendar table correct? (sorry for asking)

Make a small adjustment and try this one.

Is Holiday = 
LOOKUPVALUE(CountriesHolidays[Is_country],CountriesHolidays[ds_holidays],'calendar'[Date],CountriesHolidays[Is_country],1)

 

If this doesn't work are you abble to share a sample file so I can check if there is something else with the structure of your data?

If the information is sensitive you can share it in private message (the files can be share by onedrive, googledrive, we transfer or similar links).


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Yes, Is_Holiday is in my Calendar table.

It stills get me only 3 row with '1':

FredericoMM_0-1598604271467.png

How should I send you, @MFelix ?

Hi @FredericoMM ,

 

The issue was that in my test file I did not had repeated values in the dates for holidays now it works properly:

 

Use the formula below:

Is Holiday = 
IF (
    COUNTROWS (
        FILTER (
            CountriesHolidays;
            CountriesHolidays[ds_holidays] = 'Calendar'[Date]
                && CountriesHolidays[Is_country] = 1
        )
    ) >= 1;
    1;
    0
)

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @FredericoMM ,

 

Can you send it trough private message on a onedrive, google drive, wetransfer or similar link, please.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



amitchandak
Super User
Super User

@FredericoMM , pivot on country and try have holiday columns country wise and then join on date.  otherwise left join on the date table should work

https://radacad.com/pivot-and-unpivot-with-power-bi

Hi,

 

I can't pivot cause I don't have access to the sources, therefore I am not able to use PowerQuery for that.

 

I tried to left join as you suggested, but I couldn't do it. How should I left join this case?

 

Thanks!

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.