How to adjust the below solution source
to show census year (CY) which starts 16th of April and ends 15th of April?
(i.e.: for dates between '2020-04-16' AND '2021-04-15': 'CY2020-21', for dates between '2019-04-16' AND '2020-04-15': 'CY2019-20, and so on).
Financial Year =
VAR fy =
IF (
MONTH ( 'Dates'[Dates] ) <= 3,
VALUE ( FORMAT ( 'Dates'[Dates], "YY" ) ) - 1,
VALUE ( FORMAT ( 'Dates'[Dates], "YY" ) )
)
RETURN
CONCATENATE ( "FY", CONCATENATE ( fy, CONCATENATE ( "/", fy + 1 ) ) )
You can do this a bit more cleanly as follows:
CY =
VAR yr = FORMAT ( STARTOFYEAR ( 'Dates'[Date], "4/15" ), "YY" )
RETURN
"CY" & yr & "-" & yr + 1
Note: For this to work properly for the earliest year, the Dates table should start at the beginning of the census year.
Related
I have a Power BI visual as below. There are 3 matrices. I have a DateDimension (or) Calendar table called Dates2.
I use two measures, one a regular measure (called 'Count'), the other a parallel period comparison of the measure (called 'Count_PreviousYear'). I use SAMEPERIODLASTYEAR DAX function for the latter.
1)
Count = COUNTA(TableX[ColumnY])
--Measure with name 'Count'--
2)
Count_PreviousYear = CALCULATE
(
[Count],
SAMEPERIODLASTYEAR(Dates2[Date])
)
--Measure with name 'Count_PreviousYear'
--this measure uses Time Intelligence function - SAMEPERIODLASTYEAR--
Both 'Count' and 'Count_PreviousYear' (obviously) are not YTD (YearToDate) values.
A third measure for the percentage change across periods is computed as below:
3)
PercentageChange = IF(
ISBLANK([Count]) || ISBLANK([Count_PreviousYear]),
BLANK(),
(([Count] - [Count_PreviousYear])/[Count])
)
Kindly ignore the fact that a keyword used as a measure name;
I have used the name 'Count' only for clarity; in my actual report,
I have proper names
The % change measure works fine, but one issue:
For the period change from 2020 to 2021, i.e. in the third row of the last matrix (for the row value 2021), the total (i.e. the % change value) is not appropriate.
I need to replace -737.21% with - 23.98 %.
This is because , I need to compute the Total for 2020, only by adding the values for the months of January and February, i.e. 428 + 430 = 858. (not 5794, which is for all the 12 months).
Since 2021 has only two months - January and February, I don't want to compare two months of 2021, with all the 12 months of 2020. Rather, I want two months of 2021 to be compared with the corresponding 2 months of 2020.
Essentially I need {(692-858)/692} * 100 = -23.98%
Currently, I see {(692-5794)/692} * 100 = -737.21%
Can someone help me achieve this?
Count Previous Year =
IF (
HASONEVALUE ( Dates2[Month] ),
IF (
[Count] <> BLANK (),
CALCULATE ( [Count], SAMEPERIODLASTYEAR ( Dates2[Date] ) )
),
IF (
HASONEVALUE ( Dates2[Year] ),
CALCULATE (
[Count],
DATESBETWEEN (
Dates2[Date],
EDATE ( MIN ( Dates2[Date] ), -12 ),
EOMONTH ( MAX ( [FactTable[Date] ), -12 )
)
)
)
)
Count_PreviousYear = IF (
(HASONEVALUE(Dates2[Year]) = TRUE && HASONEVALUE(Dates2[MonthName]) = TRUE),
CALCULATE
(
[Count],
SAMEPERIODLASTYEAR(Dates2[Date])
),
IF (
(HASONEVALUE(Dates2[Year]) = TRUE && HASONEVALUE(Dates2[MonthName]) = FALSE),
CALCULATE (
[Count],
DATESBETWEEN (
Dates2[Date],
EDATE (MIN(Dates2[Date]), -12),
EOMONTH (MAX(SourceData[Date]), -12)
)
),
BLANK()
)
)
!Output obtained as desired]1
I am stuck in the situation where I am adding a new calculated column but it's prompting me the circular dependency. The first column is calculated like:
=VAR Denominator = ( Validation_Accounts_Agreements[CalculatedClosedDateVsFirstPurchaseDate] + 1 )
VAR Sales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate] >= Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate]
)
)
VAR R6AnchorSales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate]
>= EDATE (
Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate],
-6
)
&& SalesR48NBVBySolution[invoicedate] < Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate]
&& SalesR48NBVBySolution[ClensedAnchorDesignation] = "Y"
)
)
RETURN
IF ( ISBLANK ( R6AnchorSales ),
IF ( NOT (ISBLANK ( Validation_Accounts_Agreements[CalculatedFirstAnchorPurchaseDateAfterGTWClosedDate] )
)
&& ISBLANK ( R6AnchorSales ),
DIVIDE ( Sales, Denominator ) * 12
)
)
The next column I want to create here is:
=VAR Denominator = ( Validation_Accounts_Agreements[CalculatedClosedDateVsFirstPurchaseDate_SLN] + 1 )
VAR Sales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate] >= Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN]
)
)
VAR R6AnchorSales =
CALCULATE (
SUM ( SalesR48NBVBySolution[TotalSales] ),
FILTER (
SalesR48NBVBySolution,
SalesR48NBVBySolution[invoicedate]
>= EDATE (
Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN],
-6
)
&& SalesR48NBVBySolution[invoicedate] < Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN]
&& SalesR48NBVBySolution[ClensedAnchorDesignation] = "N" && CALCULATE(MAX('CAM Alignment'[NodeCd_L3])=="C3-10-00015")
)
)
RETURN
IF ( ISBLANK ( R6AnchorSales ),
IF ( NOT (ISBLANK ( Validation_Accounts_Agreements[CalculatedFirstPurchasedateAfterGTWClosedDate_SLN] )
)
&& ISBLANK ( R6AnchorSales ),
DIVIDE ( Sales, Denominator ) * 12
)
)
Here is more info about my model::
In the above picture, the yellow highlighted columns I am using to create the calculated column 1 (calculated Annualization).The red circled columns are being used to create column 2 ( calculated Annualization_SLN).both sets of columns are almost similar (changes in the filter).But when I am trying to create column 2 ( calculated Annualization_SLN) that time I am getting this error of circular dependency; which is dependent on column 1.
In general, according to best-practice avoid extensively using Calculated Columns. Instead, add them in your data source (back-end) or use M-Query.
In order to answer your question precisely, you need to share more information about your model (i.e. relationships). However, we can provide you some guidelines referring to this article in order to avoid circular dependencies.
Quoting the conclusion of the article:
Most of the time, circular dependencies occur when you use calculated tables. You can easily avoid them by paying attention to your choice of functions. The difference between DISTINCT and VALUES, or between ALL and ALLNOBLANKROW is a subtle difference. But once you get used to it, your code will be safer when it comes to relationships and circular references.
I have a SQL query which calculated the difference between the current weekday and previous weekdays in terms of weeks and I need to translate this to DAX query.
SQL :
DATEDIFF(Week,Getdate(),
DATEADD (WEEK, CAST (RIGHT(CAST ([Code] AS nvarchar),2) AS int),
DATEADD (YEAR, ([Code] / 100)-1900, 0)) - 4 -
DATEPART(dw,
DATEADD (WEEK, CAST (RIGHT(CAST ([Code] AS nvarchar),2) AS int),
DATEADD (YEAR, ([Code] / 100)-1900, 0)) - 4) + 1)
AS [WeekIndex]
enter code here
Expected Result: If code = 201821 then WeekIndex has to be -53 as the current week is week 22
I think you are looking for something like this:
[Measure] :=
VAR code = "201821"
VAR code_year = LEFT ( code, 4 )
VAR code_week = RIGHT ( code, 2 )
VAR code_date = DATE ( code_year, 1, -2 ) - WEEKDAY ( DATE ( code_year, 1, 3 ) )
+ code_week * 7
RETURN
DATEDIFF ( TODAY (), code_date, WEEK )
VAR [code_date] will return the monday of the given VAR [code] as a datevalue
I have a Power BI report that calculates the number of jobs due in a month and reports on how many jobs are completed on time. The report works well except the measure totals do not add up correctly like the table columns do.
I have measures in place for:
Done on time = Jobs completed in their due month
Outside time = Jobs completed after when they were due.
Incomplete = Used to identify incomplete jobs
% Perf = Percentage of jobs completed on time."
Other fields:
DUE = Due Date
completed = job completion date
I have found a possible answer to this using (HASONEFILTER) but cannot get it to work.
MEASURES
Done on time =
VAR DueMonth = MONTH ( FIRSTDATE ( Table1[due_date] ) )
RETURN
CALCULATE (
[Due],
FILTER ( Table1,
MONTH ( Table1[completed] ) = DueMonth || MONTH (
Table1[completed] ) = DueMonth -1 || MONTH ( Table1[completed] ) = DueMonth +1
)
)
Outside time =
VAR DueMonth = MONTH ( FIRSTDATE ( Table1[due_date] ) )
RETURN
CALCULATE (
[Due] - [Done on time],
FILTER (
Table1,
MONTH ( Table1[completed] ) <> DueMonth || MONTH ( Table1[completed] ) = DueMonth -1 || MONTH ( Table1[completed] ) = DueMonth +1 ||
NOT ISBLANK ( Table1[completed] )
)
)
% Perf =
DIVIDE (
[Done on time],
[Due],
BLANK()
) * 100
Results would be properly totaled column measure's, screenshot below of existing output.
I have been trying to get this DAX expression to show me cumulative searches for last financial year. Here is an example of the information;
Fiscal Week Fiscal Year Searches Brand
1 14 1000 Example1
1 15 1200 Example1
2 14 1000 Example1
2 15 1200 Example2
My formula below is working a little, but when I apply an slicers to the data it breaks in PowerBI. i.e. if I slice by another field, like brand.
Cum. Searches PY =
IF (
HASONEVALUE ( 'data'[Fiscal Year] ),
CALCULATE (
SUM ( 'data'[Searches] ),
FILTER (
ALL( 'data' ),
'data'[Fiscal Year.] = VALUES ( 'data'[Fiscal Year] ) - 1
&& CONTAINS(
VALUES ( 'data'[Fiscal Week] ),
'data'[Fiscal Week],
'data'[Fiscal Week] )
)
),
BLANK ()
)
I'd appreciate any pointers to where I'm going wrong? Thanks in advance.
I think it can be simplified, I dont understand the need for the HASONEVALUE or CONTAINS functions. I would use something like the following for your measure:
Cum. Searches PY:= CALCULATE(
SUM( Table1[Searches] ),
FILTER(
ALL( Table1[Fiscal Year] ) ,
Table1[Fiscal Year] = MAX( Table1[Fiscal Year] ) - 1
)
)
With that sample data above, this will produce results of:
Example1 2000
Example2 (Blank)
If that's not your expected result, then explain exactly what you want.