IF and && statements with Dates - powerbi

Needed help where I have a table with 2 date columns and a status column, I am trying to return a value based on the condition that if both dates are equal and status is "resolved" then return a text value saying "resolved on the same day" or keep it blank
I have created a new column in my table where I am trying to see if Date1 = Date2 and status is complete then return 'resolved on the same day' else return blank. I am sure I am going wrong somewhere as I am new to this, any help would be much appreciated.
Column1= IF('ALL CASES'[Date1] = 'ALL CASES'[Date2] && 'ALL CASES'[Status]="Resolved","Resolved on the same day")

This is the result when you use your formula in a calculated column:

Related

Add previous month column DAX Power BI

I have a fact table which has 'Last Data Update' column that shows current month date(mm/dd/yyyy), 06/13/2022.
I am trying to add column called 'report month' that returns a value that shows previous month/year 05/2022 to create relationship with calendar table.
=Date.Month([Last Data Update])-1
I have used this code, but this only returns 5 and it is in number format.
is there a way to return 05/2022 in DAX ?
Thanks in advance.
This is M, not DAX. Replace your custom column with the following code:
Text.PadStart( Text.From(Date.Month([Last Data Update])-1),2,"0") &"/"& Text.From(Date.Year([Last Data Update]))
It worked for we with this 3 simple steps:
Step 1: Create a column with current year (True/False statement) by using:
CurrentYear = IF(YEAR([Last Data Update])=YEAR(NOW()),1,0)
Step 2: Create a column that will indicate if the current date (based on column "Last Data Update") belongs to previous month or not (True/False statement).
PreviousMonth = IF([CurrentYear]=1 && (MONTH(TODAY())-1)=MONTH([Last Data Update]),1,0)
Step 3: Create a filter on your visual where you select filter "PreviousMonth" with value "1" to show dates only from previous month).
If you like it. Don't forget to rate it.
Success,
Mark
This month-year
FORMAT( [Last Data Update], "mm/yyyy")
previous month
FORMAT( DATEADD([Last Data Update],-1,Month), "mm/yyyy")

I am tracking my investments - If column 2 (contains my contribution) is less than column 3 (investment return), return column 1 (date of occurrence)

I have a spreadsheet on Google Sheets that tracks my investment. Based on average returns I have calculated the average return rate over the years.
First column no.1 has a list of dates. Column no.2 has my contribution. Column no.3 has the average return.
I would like to do the following if statement: if(column2<column3)return(column1)
This is so I can see the date my returns become more than my contributions.
This code assumes that column1 is A, column2 is B and column3 is C.
the formula for the IF statement is:
first the thing you want to test
next the return value if true
last the return value if false.
I have set false to return 0, but you might want something else.
=IF($B1<$C1;$A1;0)

Calculated Column for first 5 working days in each month

I wanted to do calculated column in my calendar table in Power BI. The calculated column should show "1" for the first 5 working days in each month in the calendar table, the rest of the days should be "0" . I tried to come out with the formula shown below
tick = CALCULATE(COUNT('Calendar'[Weekend - weekday]), 'Calendar'[IsWorkingDay] = TRUE)
But it shows "1" for all the working days but the desire output is the first 5 working days of each month. Anyone could help me
Suppose this is your original table with new column for Weekday-weekend, you can calculate the new column to display 0 for first five working days using rankx & If, followed by 0 and blank for other case, here is the dax formula:
Remark: Both 1 and 0 need to with quotation mark, as using with "" without convert to string will cause Data is variant type error.
tick1 =
var rank1 = RANKX(FILTER(Sheet1,Sheet1[Weekday-Weekend] = "Weekday" && Sheet1[Period] = EARLIER(Sheet1[Period]) ),Sheet1[Day],,ASC)
return
IF(Sheet1[Weekday-Weekend] = "Weekday" && rank1 >=1 && rank1 <=5, "1",
IF(Sheet1[Weekday-Weekend] = "Weekday", "0",""))
The table with add column

Dax Finding date based on Criteria calculated Column

I couldn't find an answer for my issue elsewhere, so trying my luck here.
I have sales table and my final result should determine if there were sales made for same person in specific period of time, for example within 7 business days. for example:
For ID 123 I have to flag it that sale for products A,B,C where within specified period.
For ID 1234 only sales of products A and B meet the criteria product C was sold in irrelevant time frame.
I've created a date table with indicators that determine for each date if the date is a working day, but i am struggling to calculate the relevant last working day
For example: I need that for 01/01/2019 i will get 10/01/2019 date, based on NUMOFDAYS and FinalWorkday = TRUE, which basically means that i have to count NUMOFDAYS times TRUE statement for each date and return corresponding date.
After that step done I think that it would be pretty easy for me to determine if the sale for a person was made in specific time frame.
If someone can give me direction for that much appreciated
Thank you in advance
You could use a DateTable like this one:
I used the following DAX-expressions for the calculated columns:
nrDays = 7
isWorkDay = WEEKDAY('DateTable'[Date],2) < 6
rankWorkingDays = RANKX ( FILTER ( DateTable, DateTable[isWorkDay] = TRUE () ),
DateTable[Date] , , ASC )
LastWorkDay = LOOKUPVALUE ( DateTable[Date],
DateTable[isWorkDay], TRUE (),
DateTable[rankWorkingDays], DateTable[rankWorkingDays] + DateTable[nrDays])
This issue can be solved by the following, since three are non-working days/holidays we can filter them out via POWERQUERY, than add an Index Column and Another column Which is basically Index column + Number of days wanted, then simply merge duplicate of dates query on Index+number of days wanted column on Index column. And we get the correct date

Power query - Calculated column to check date

I have a column "MYDATE" with dates (dd/mm/yyyy) and I need to create a calculated column that checks if the date is today's date.
I have tried '=if [MYDATE]=DateTime.LocalNow() then "Yes" else ""' this butit did not work because of the different format.
Any suggestion?
You can use Date.IsInCurrentDay([MYDATE])
or closer to your attempt:
if [MYDATE] = DateTime.Date(DateTime.LocalNow()) then "yes" else ""
Note that both solutions check against the last refresh date.