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
PowerBIExplorer
Frequent Visitor

Excel to Power BI Dax

Hi, 

 

In column 'OK' - # of month is a calculated column in excel with the following formula:

=IF(OR(O4="",DAYS($C$1,O4)>365),13,IF(YEAR(O4)=YEAR($C$1),MONTH($C$1)-MONTH(O4),12+MONTH($C$1)-MONTH(O4)))

 

 

Test.PNG 

 

I'm not sure sure I can create recreate this formula in Power BI... I can't find the equalivence for days in dax....

 

 

Thanks.

1 ACCEPTED SOLUTION

@PowerBIExplorer,

Please review the DAX in the PBIX file below.

https://1drv.ms/u/s!AhsotbnGu1Nok0Ck5EKND2-5SLIk

Regards,
Lydia

Community Support Team _ Lydia Zhang
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

3 REPLIES 3
TomMartens
Super User
Super User

Hey,

 

it's little bit difficult for totally understand your requirement from the screenshot and your Excel Formula. It would be really helpful if you created some sample data in a PBIX file, upload this file to onedrive or dropbox and share the link 😉

 

But nevertheless maybe this gets you started (I assume you want to create a calculated column):

Your Excel O4 = "" can be translated to DAX like so ISBLANK('tablename'[ColumnameFromO4])

 

Assuming that the data type of your column O4 is something like datetime or date than you can use the DAX formulas YEAR('tablename'[ColumnameFromO4]), MONTH('tablename'[ColumnameFromO4])

You can use DATEDIFF (https://msdn.microsoft.com/en-us/query-bi/dax/datediff-function-dax) to calculate the duration between two dates for a certain unit like days

 

Overall I would suggest to use the DAX formula SWITCH to avoid cluttered nested if statements like so:

SWITCH(
    TRUE()
    ,your first condition, 13
    ,your 2nd condition, ...
,maybe a something else :-) )

 Hopefully this gets you started

 

Regards

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thank you, here is a sample dataset of what I'm working with. 

 

https://app.box.com/s/ckaqvj9maiy5gt6jdsqy8h51mwgkr3uq

 

Columns J and K are the columns I need to replicate in Power BI as calculated columns.

 

I'm not sure to input the data for "Measures as of'' into Power bi since it's not a whole column. Maybe I can replace the cell in the formula with the actual dates, but I find that tedious if I need to update it everytime I update the excel sheet. 

 

 

@PowerBIExplorer,

Please review the DAX in the PBIX file below.

https://1drv.ms/u/s!AhsotbnGu1Nok0Ck5EKND2-5SLIk

Regards,
Lydia

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

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.