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
eliasayy
Impactful Individual
Impactful Individual

Using IF to multiply columns according to date

Hello, i am trying to multiply 2 columns say cost and number of sales according to the date. so if date is before 2022, the cost is 10 and fixed but if the date is in 2022 or later, i calculate the given cost in the column.

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@eliasayy missing info about your model, but let's try (assuming you have all the columns in one table):
In case yor need a calculate column than adjust this code to your model needs:

Column = Table[Quantity] * IF( YEAR('Table'[Date]) < 2022, 10, Table[Cost])


In case it's a measure go with this:

Measure = 
SUMX(	
    'Table',
    Table[Quantity] * IF( YEAR('Table'[Date]) < 2022, 10, Table[Cost])
)

 
In case it answered your question please mark this as a solution for community visibility. Appreciate Your Kudos 🙂

View solution in original post

13 REPLIES 13
SpartaBI
Community Champion
Community Champion

@eliasayy missing info about your model, but let's try (assuming you have all the columns in one table):
In case yor need a calculate column than adjust this code to your model needs:

Column = Table[Quantity] * IF( YEAR('Table'[Date]) < 2022, 10, Table[Cost])


In case it's a measure go with this:

Measure = 
SUMX(	
    'Table',
    Table[Quantity] * IF( YEAR('Table'[Date]) < 2022, 10, Table[Cost])
)

 
In case it answered your question please mark this as a solution for community visibility. Appreciate Your Kudos 🙂

eliasayy
Impactful Individual
Impactful Individual

like i have sales per day in this table but cost in another table

eliasayy
Impactful Individual
Impactful Individual

Thank you very much, all data are in the same table. but what if data are in different table. and for more clarity, in a table, i have cost and sales per day, i want to find cost per day. before 2022, the cost was fixed at 10$ but after 2022, i have variable cost everyday they change

@eliasayy  I need more info. Can you share a sample data (in tables, not pictures) but with all the columns in the table and the relationship between the two tables?

eliasayy
Impactful Individual
Impactful Individual

the thing is the data is confidential i will try to explain.

i have 2 tables. both contain sales per day and only table one contains the cost.

i need to find the cost per day which is cosst*sales per day, but if date <2022 it was 10$ fixed, but after 2022, i have a different cost everyday and have to multiply the cost column with the sales per day column but its in different table. i created a realationship between the tables which is the date is the rlationship

@eliasayy still not sure 😞
Can you maybe create a fake data that you could upload as tables here, and also show exactly what is the relationship (who is the one side who is the many)

eliasayy
Impactful Individual
Impactful Individual

ok i will try but im fairly new here so how do i create a table here?

@eliasayy you can create it in excel and just copy paste here.

P.S. I will maybe be able to get to only tomorrow but we'll try today. Already late evening here 🙂

eliasayy
Impactful Individual
Impactful Individual

The relationship is date i managed the relationship as the date

 

Table 1      Table 2   
 datecostsalescost per day   datesalescost per day
 10/5/2021"cost is fixed at 10 because <2022"70"=" cost *sales per day   30/4/202170"="  table1[cost] *sales per day
 10/20/2021 40    9/29/202167 
 1/5/2022321    1/5/202250 
 9/4/2022668    9/4/2022190 
 9/5/2022755    9/5/202290 
 9/6/2022365    9/6/202255 
 9/7/2022489    9/7/2022120 

 

@eliasayy what is the granulrity of the relationship? 1:1 , 1:m? In case it's 1:m who is the 1 and who is the mant? in case it's 1:1 why don't you just join the tables?

eliasayy
Impactful Individual
Impactful Individual

im not gonna lie to you, i have no idea what you meant, i am new to dax abd stuff

@eliasayy  No worries. I will pm you

eliasayy
Impactful Individual
Impactful Individual

very much appreciated

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.

Top Solution Authors