Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 213819

Can this be done in Power BI?

$
0
0

I use this code in SSRS whenever the report is run

 

declare @SlDto date = '20151231'

select
	Period,
	case
		when (case when DATEPART(YY,dateadd(mm,0,@SlDto))-DATEPART(YY,dateadd(mm,-2,@SlDto)) > 0 then 1 else 0 end) = 0 then cast(YEAR(Period) AS varchar(4))
		else
			cast( year(@SlDto)-1+(case when MONTH(Period) between 1 and MONTH(@SlDto) then DATEDIFF(YY,@SlDto,Period) else DATEDIFF(YY,@SlDto,Period) +1 end) as varchar(4))+
				'/'+cast( year(@SlDto)+(case when MONTH(Period) between 1 and MONTH(@SlDto) then DATEDIFF(YY,@SlDto,Period) else DATEDIFF(YY,@SlDto,Period) +1 end) as varchar(4))  
	end as yy,
	case 
		when DATEPART(mm,Period) in (DATEPART(MM,dateadd(mm,0,@SlDto)), DATEPART(MM,dateadd(mm,-1,@SlDto)), DATEPART(MM,dateadd(mm,-2,@SlDto))) then 4
		when DATEPART(mm,Period) in (DATEPART(MM,dateadd(mm,-3,@SlDto)), DATEPART(MM,dateadd(mm,-4,@SlDto)), DATEPART(MM,dateadd(mm,-5,@SlDto))) then 3
		when DATEPART(mm,Period) in (DATEPART(MM,dateadd(mm,-6,@SlDto)), DATEPART(MM,dateadd(mm,-7,@SlDto)), DATEPART(MM,dateadd(mm,-8,@SlDto))) then 2
		when DATEPART(mm,Period) in (DATEPART(MM,dateadd(mm,-9,@SlDto)), DATEPART(MM,dateadd(mm,-10,@SlDto)), DATEPART(MM,dateadd(mm,-11,@SlDto))) then 1
	end as Qrt,
	DATEPART(mm,Period) as mth,

 

Depending on the date @SlDto it calculates new Quarters and Years. It is not ordinary Year and Quarter calculations.

 

I hope that this can be done in Power BI depeding on a slicer choice.


Viewing all articles
Browse latest Browse all 213819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>