Power BI exchange rate calculation - date

I am a newbie in Power BI desktop.
We have a Sales transaction table with RateDate, orderAmount and transaction Currency
Also, we have an exchange rate table with BaseCurrency(standard currency i.e. USD,EUR and INR) ,target currency, effective date and Rate.
For analysis, We need to convert the Salesamount in any of the Base Currency i.e USD/INR/EUR as per the rate date-effective date mapping on the fly.
How can I achieve that?
I tried following DAX code,
AmountUSD = SUMX(Fact_SalesOrder,[OrderAmount]/lookupvalue(CurrencyRates[Rate],CurrencyRates[Effective Date],Fact_SalesOrder[RateDate],CurrencyRates[Base Currency],"USD",CurrencyRates[Target Currency],Fact_SalesOrder[Currency]))
But it results in 'infinity' value.

Finally got it :)
Just need 2 measures: SalesAmount for Sales and Selected currency for selection.
Selected Currency = VALUES('ReportingCurrencies'[Currency])
And
SalesAmount = SWITCH(TRUE(),
[Selected Currency] = "EUR",SUMX(Fact_SalesOrder,[OrderAmount]/lookupvalue(CurrencyRates[Rate],CurrencyRates[Effective Date].[Date],Fact_SalesOrder[RateDate].[Date],CurrencyRates[Base Currency],"EUR",CurrencyRates[Target Currency],Fact_SalesOrder[Currency],1)),
[Selected Currency] = "USD",SUMX(Fact_SalesOrder,[OrderAmount]/lookupvalue(CurrencyRates[Rate],CurrencyRates[Effective Date].[Date],Fact_SalesOrder[RateDate].[Date],CurrencyRates[Base Currency],"USD",CurrencyRates[Target Currency],Fact_SalesOrder[Currency],1)),
[Selected Currency] = "INR",SUMX(Fact_SalesOrder,[OrderAmount]/lookupvalue(CurrencyRates[Rate],CurrencyRates[Effective Date].[Date],Fact_SalesOrder[RateDate].[Date],CurrencyRates[Base Currency],"INR",CurrencyRates[Target Currency],Fact_SalesOrder[Currency],1)))

Related

DAX Calculate Billing Days Between Two Variable Dates

I have a dimdate table that is represented below. I have each day flagged as BusinessDay Y/N. I also have a DimSalesRep table that has a daily goal for each rep. I want to be able to allow users to input a StartDt and EndDt with filters on the report and have a calculated column look at the business days between those dates. I can calculate daysbetween with defined dates but I am unsure how I would use DAX with variable dates that are applied through Report filters.
I should also note I am not sure how best to handle a startdt and enddt filter based of the column, TheDate
Cheers!
Reference your dimdate table twice
StartDate = 'dimdate'
EndDate = 'dimdate'
and use this measure:
Num BusinessDays =
CALCULATE(
COUNTROWS('dimdate'),
'dimdate'[BusinessDay] = "Y",
'dimdate'[Date] >= SELECTEDVALUE(StartDate[Date]),
'dimdate'[Date] <= SELECTEDVALUE(EndDate[Date])
)

How to calculate total sales as of first day of the current month as Previous month sales in power BI

I have salesamount column and the saledate column in my table. so I need to calculate total sales for each month based on below calculation.
total sales for current month=sum(salesamount) as of 1st day of the next month
for example sales of December-2021 should be calculated based on the total sales as on Jan-1-2022. total sales for January should be blank until Feb-1-2022 as it should be the total sales as on feb-1-2022. I am very much confused how we can achieve this in Dax. Really appreciate your help.
If I understand your question correctly, you can use the following DAX measure:
Total Sales =
var currentDate = MAX(myTable[saleDate])
var firstOfMonth = DATE(YEAR(CALCULATE(MAX(myTable[saledate]), ALL(myTable))),
MONTH(CALCULATE(MAX(myTable[saledate]), ALL(myTable))), 1)
var result = SUM(myTable[salesamount])
Return IF(currentDate < firstOfMonth, result)
This will take the current date of the report context and compare it to the 1st of the current month. If the currentDate is less than the 1st of the current month, the result will be calculated.
If your dataset has a Date table, you can replace the 'myTable[saledate]' references with a reference to the Date column in your date table.
With some sample data, here are the results:
(I added the firstOfMonth column for demonstration purposes)

Is there a way to calcullate difference between 2 dates (first one and last one) in dax / powerbi?

For example i have a have this excel file with the date of stage change of every candidate
What i'm trying to do is to calculate how many days on average it's taking to a candidate to move from technical test sent to technical test review.
the problem is that sometimes candidates are moved by mistake and the system records both movements.
so what i need is a way to calculate average datediff between firstdate of technical test sent and lastdate of technical test review for every candidate.
Any ideas how? Please help :(
Please try with these 3 measure-
min_date_tt_sent =
CALCULATE(
MIN(your_table_name[date of change]),
FILTER(
ALL(your_table_name),
your_table_name[candidate id] = MIN(your_table_name[candidate id])
&& your_table_name[stage] = "Technical Test Sent"
)
)
max_date_tt_review =
CALCULATE(
MAX(your_table_name[date of change]),
FILTER(
ALL(your_table_name),
your_table_name[candidate id] = MIN(your_table_name[candidate id])
&& your_table_name[stage] = "Technical Test Review"
)
)
date difference = DATEDIFF([min_date_tt_sent],[max_date_tt_review],DAY)
Here is the output from your sample data-

Financial Year in SSRS from date

I'm trying to get SSRS to show the financial year an issue date was placed
As an example
A date showing 01/04/2018. The financial year column would return 2018
A date showing 31/03/2018. The financial year column would return 2017
SELECT
IIF(Month(rTranslog.IssueDate)<=3, Year(rTranslog.IssueDate)-1,
Year(rTranslog.IssueDate)) AS [FY}
,rTranslog.IssueDate
,rTranslog.Site
,rTranslog.NSVCode
,rProduct.LabelDescription
,rTranslog.Ward
,SUM(rTranslog.Qty) AS Quantity
,SUM(rTranslog.Cost)/100 AS CostGBP
FROM
rTranslog
INNER JOIN rProduct
ON rTranslog.NSVCode = rProduct.NSVCode
GROUP BY
rTranslog.IssueDate
,rTranslog.Site
,rTranslog.NSVCode
,rProduct.LabelDescription
,rTranslog.Ward
Any ideas?
You can use an expression in SSRS like the one below to calculate the financial year
= Iif( Month(Fields!calendardate.Value)<=3, Year(Fields!calendardate.Value)-1, Year(Fields!calendardate.Value))
For SQL:
CASE WHEN Month(rTranslog.IssueDate)<=3 THEN YEAR(rTranslog.IssueDate)-1 ELSE YEAR(rTranslog.IssueDate) END

Create a measure to return the maximum date about the order in a fact table. (SSAS Multidimensional)

I want to create a measure which return the maximum date about Orders but before the actual day
I will write an example :
My tables here
(In my table Calendar i have the year 2016,2017,2019, and in my Order table, i have an order for 2016 and 2019,
I want the last date order but before the actual day (18/05/2017), so i want the Date 01/01/2016).
I have 2 table, a dimension Calendar and a fact table Order.
I was thinking about the function filter, so i search how to use filter in
google, and all the solutions i found use 'With' and 'Select'.
(I can't use 'With' and 'Select' when i create a measure in SSAS multidimensional).
Hope i will see your advice.
Just like this similar case in adv cube?
[max order date] return the maximum date about [Internet Sales Amount]
with member [max order date] AS
tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales Amount])).item(0).item(0).PROPERTIES( "name" )
select {[max order date] } on 0 from [Adventure Works]
if yes, then you can create a measure in your cube like this:
Create Member CurrentCube.[Measures].[max order date]
As tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales
Amount])).item(0).item(0).PROPERTIES( "name" );
if only till current day, then(following is refer to adv cube, you need do some code changes per your cube):
Create Member CurrentCube.[max order date] AS
Tail
(
NonEmpty
(
{
Head([Date].[Date].[Date]).Item(0).Item(0)--the first day in your Date dim
:
StrToMember("[Date].[Date].&[" + Format(Now(),"yyyyMMdd") + "]")-- as of current day
}
,[Measures].[Internet Sales Amount]
)
).Item(0).Item(0).Properties("name")
IDE to Write, Analyze, Tuning, Debug MDX efficiently (www.mdx-helper.com)