Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
firstch
Helper III
Helper III

Is it possible to use PRREVIOUSYEAR FUNCTION with this data?

Hi all 

Please  help me how to use PREVIOUSYEAR  function with this data that not have date table , I really need previous year yields for making report , but I'm not expert in DAX , hope someone can help me 
Thankyou, in advance

 

firstch_0-1651826862645.png

 

1 ACCEPTED SOLUTION

Hi,

 

Here is the solution calculated witha measure :

Measure PrevYear = 
VAR CurrentYear = SELECTEDVALUE( DataHarvest[year] )
RETURN
CALCULATE( SUM( DataHarvest[yields_tons] ) , DataHarvest[Year]=CurrentYear-1 )
to get that :
PrevYear.png

View solution in original post

20 REPLIES 20
AilleryO
Memorable Member
Memorable Member

Hi,

 

Since you do not have a "proper" date (ie day, month and year), why not just substract 1 to the year to get the previous one ?

With a formula like :

Prev Year Value = 
VAR CurrentYear = SELECTEDVALUE( TabDatas[Year] )
RETURN
CALCULATE( SUM( TabDatas[Value] ) , TabDatas[Year] = CurrentYear -1 )
and get that :
PrevYearValue.png
If your data are as simple as the one shown, you might not need to use Time Intelligence functions. If you want to use them then you should create a proper date columns and maybe even a date table.
 
Hope it helps
SanketBhagwat
Solution Sage
Solution Sage

Hi @firstch .
First create a Date column using your Year Column.
Date=DATE([YearColumn],"01","01").

Then create  a measure for previous Year using PrevYear=PREVIOUSYEAR(DateColumn)


Thanks,
Sanket

If this post helps, then mark it as Accept as Solution and give it a thumbs up.

Hi @SanketBhagwat  when i create date column it pop up me this

firstch_0-1651828532043.png

 

 

SanketBhagwat_0-1651829903765.png

 Do you have this brackets in your DAX at the end?

I believe you have some additional brackets at the end your formula, remove them.
Try and write the formula from scratch.

What is that first parameter which you are passsing?
You just need to pass your Year Column as your first parameter.

Check your formula once.
Thanks,
Sanket

@SanketBhagwat  I passing year column that call 'ปี' but the data type format is text 

Thanks 
First

Try changing the data format to whole number and let me know if it works.

Thanks,
Sanket

this is my DAX

firstch_0-1651829870256.png

firstch_2-1651829961988.png

 

this is my date column

firstch_1-1651829915646.png

 



Worked right?

its doesn't show the prevyear Yield sir

firstch_0-1651830398985.png

 

Why are you getting your year column values as 2557,2558..?
Check that first because the data which you provided has year column values as 2020,2021,2022....

the data that i give is the example but this one is real data both are  same structure sir

firstch_0-1651829722347.png

it doesn't work sir

Can you share a .pbix with some sample data?

@SanketBhagwat  want this as output

firstch_0-1652014972757.png

this is all data

productyearyields_tonsharvest_area_SQM
cabbage2563138,52081,543
cabbage256376,00946,512
cabbage256323,72233,364
cabbage256319,90634,440
cabbage256314,9289,434
cabbage256311,43327,028
cabbage25638,2965,169
cabbage25632,8885,618
cabbage25642,8193,747
cabbage25642,7084,147
carrot2564242,686167,504
carrot2564130,918107,222
carrot256475,73154,840
carrot256433,13338,298
carrot256430,22023,580
carrot256530,00743,806
carrot25651,1502,208
carrot25651,0843,576
carrot25651,0772,613
carrot25658932,249
carrot2565451567
carrot2565301435
tomato2562260348
tomato2562219328
tomato2562192295
tomato2557160140
tomato25574068
carrot2558234,514167,004
carrot2558124,495108,257
carrot255871,18255,192
carrot255831,92223,155
carrot255830,80937,815
carrot255828,85023,283
carrot255824,96544,163
carrot25589,41630,852
carrot25587,92428,655
carrot25586,9825,066
carrot25586,1928,878
carrot25584,52214,309
carrot25584,1048,390
carrot25583,3943,470
carrot25583,2597,250
carrot25581,6331,638
carrot25581,1752,202
carrot25581,0453,537
carrot25589721,449
carrot25588232,228
carrot25587732,082
carrot25585771,953
carrot2558373631
carrot2558326454
carrot2558267430
carrot2558240354
carrot2558165167
carrot255878170
carrot25583972
carrot2558119
carrot2559187,790171,092
carrot2559119,814127,250
carrot255959,67656,234
carrot255930,39337,929
carrot255929,90424,178
carrot25594632,238
carrot2559251646
carrot2559187536
carrot2559177442
carrot25591385,056
carrot2559119126
carrot255952182
carrot255949395
carrot25593487
carrot2559126
carrot2560284,874173,672
carrot2560114,252130,911
grape2557102,908126,688
grape255748,36680,088
grape255738,35654,405
grape255723,93132,177
grape255716,71023,656
grape255710,55913,894
grape255710,27012,918
grape25578,89512,387
grape25578,34220,546
grape25576,89511,259
grape25574,0494,855
grape25572,0787,318
grape25571,6853,187
grape25571,6272,815
grape25571,3812,019
grape25579711,317
grape2557624886
grape2557484918
grape25574831,189
grape2557406652
grape2557247449
grape255796278
grape25571143
grape255881,660127,594
grape255831,12479,359
grape255818,39533,782
grape255814,26426,231
grape255813,26054,119
grape25586,97412,670
grape25586,21519,883
grape25585,86613,858
grape25585,19211,800
grape25584,78712,106
grape25583,2136,933
grape25582,6764,613
grape25581,2662,610
grape25581,1513,059
grape25581,0431,989
grape25586601,246
grape25586591,039
grape2558462895
grape25583921,109
grape2558296638
grape2558246449
grape255898305
grape25581243
grape255968,871129,339
grape255929,15080,126
grape255925,22654,308
grape255915,64934,917
grape255913,19126,258
grape25595,95220,626
grape25595,94312,670
grape25595,27913,945
grape25594,28011,974
grape25594,10611,774
grape25592,7936,621
grape25592,4724,490
grape25591,1192,534
grape25598312,924
grape25595891,161
grape2559462895
grape25594501,475
grape25594341,404
grape2559249599
grape2559118449
grape2559100493
grape255991343
grape25591243
grape2560112,309129,537
grape256024,89781,097
grape256024,60335,047
grape256016,76626,204
grape256013,89952,449
grape25604,87813,780
grape25603,3049,982
grape25603,23712,367
grape25601,3884,271
grape25606982,948
grape25606831,369
grape25606382,292
grape256061012,218
grape25603271,447
grape25603186,621
grape25602941,429
grape2560281599
grape2560277503
grape2560194518
grape256096340
grape25608520,225
grape256083449
grape25601560
grape256150,719129,807
grape256140,24083,713
grape256124,09549,815
grape256114,58336,675
grape256111,39920,307
grape25618,29113,615
grape25618,27427,141
grape25616,64212,247
grape25615,78712,871
grape25614,75710,697
grape25613,3076,861
grape25612,3304,052

Thankyou in advance @SanketBhagwat 

firstch

Hi,

 

Here is the solution calculated witha measure :

Measure PrevYear = 
VAR CurrentYear = SELECTEDVALUE( DataHarvest[year] )
RETURN
CALCULATE( SUM( DataHarvest[yields_tons] ) , DataHarvest[Year]=CurrentYear-1 )
to get that :
PrevYear.png

Thanks you so much sir, it's work now

firstch_0-1652032911284.png

😀

how to share pbix file

ok i willl share it please wait .

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.