Forum Discussion
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.
Anonymous 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 🙂
13 Replies
- SpartaBI
Community Champion
Anonymous 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 🙂- AnonymousNot applicable
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
- SpartaBI
Community Champion
Anonymous 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?
- AnonymousNot applicable
like i have sales per day in this table but cost in another table