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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sakshikaul
Helper III
Helper III

Graph output not showing Correct

HI,

I want in the following graph when I select year as 2021(current year) then it should only show values of all the months of current year ie Jan and feb for 2021.

And automatically previous year (2020 all the months ie Jan -Dec should be shown in graph) on selection of 2021(current Year)

 

But in my following graph data for 2021 is showing me all the months( Jan -Dec( whereas it should only show jan , feb) and 2020 also data is captured for all the months . Please help

 

Year selected=2021

sakshikaul_0-1616310842019.png

Following is the DAX written in Power BI

MaxYear1_HAWB = If(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",CALCULATE(SUM(DBALLSTAT[Profit])/1000,FILTER((DBALLSTAT),DBALLSTAT[Eco_year]=MAX(DBALLSTAT[Eco_year])),FILTER(Group_Logic,Group_Logic[Load Type]="HAWB")))

 

whereas I am basically migrating qlikview application to power BI so in qlikview the expression is written as 

=if(substringcount(Concat(distinct '~' & [Load Type] & '~' ,'|'),'~HAWB')=1,


SUM({<Eco_year = {'$(Maxyear)'},[Load Type]={'HAWB'}>}(Profit)/1000)

,'')

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @sakshikaul ,

In order to make the data output correct, I created a table to store the 12 months from January to December. Associate it with the month column of the DBALLSTAT table, and set the filtering direction to single. Then modify the measure:

v-kkf-msft_0-1616754325342.png

previous year = 
var Selectvalue =    
CALCULATE(
        [SelectYear],
        FILTER(
            ALL('DBALLSTAT'),
            'DBALLSTAT'[Eco_year] = MAX('DBALLSTAT'[Eco_year])-1
            && DBALLSTAT[Month] = MAX(DBALLSTAT[Month])
        )
    )
var notselect = 
    CALCULATE(
        [SelectYear],
        FILTER(
            ALL('DBALLSTAT'),
            'DBALLSTAT'[Eco_year] = MAXX(ALL(DBALLSTAT),'DBALLSTAT'[Eco_year])-1
            && DBALLSTAT[Month] = MAX('Month'[Column1])
        )
    )
return 
    IF(
        ISERROR(ALLSELECTED(DBALLSTAT[Eco_year])),
        notselect,
        IF(
            ALLSELECTED('DBALLSTAT'[Eco_year])=2021,
            notselect,
            Selectvalue
        )
    )

v-kkf-msft_1-1616754740762.png

In my sample data, I have successfully fulfilled your requirements, please check the PBIX file for more details.

View solution in original post

39 REPLIES 39
v-kkf-msft
Community Support
Community Support

Hi @sakshikaul ,

I added a condition about the date ie DBALLSTAT[Date] to the formula, you try to see if it can get the result you want. If it is unsuccessful, please provide some sample data and relationships between tables.  

MaxYear1_HAWB = 
If(
  SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
  CALCULATE(
    SUM(DBALLSTAT[Profit])/1000,
    FILTER(
      (DBALLSTAT),
      DBALLSTAT[Eco_year]=MAX(DBALLSTAT[Eco_year])
      && DBALLSTAT[Date] <= EOMONTH(TODAY(),-1)
    ),
    FILTER(
      Group_Logic,
      Group_Logic[Load Type]="HAWB"
    )
  )
)

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi,

Earlier on selecting 2021 filter the data was not getting filtered for 2021. It was showing all the months for 2021 ie jan to dec and same for 2020

but now I have solved one issue like now on selecting year =2021 I am getting data for jan and feb only which is correct but for 2020 I am not getting values. please help 

Expression written for current Year

Maxyear1_hawb=

var summaryA=MAX(DBALLSTAT[Eco_year]) var summaryB=If(
SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
CALCULATE(
SUM(DBALLSTAT[Profit])/1000,
FILTER(
(DBALLSTAT),
DBALLSTAT[Eco_year]=summaryA
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"
)
))
return summaryB

 

expression for prev year

PrevYear1_HAWB = var Summary_hawb_prev=MAX(DBALLSTAT[Eco_year])-1 var summary_hawb_prevB= If(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",CALCULATE(SUM(DBALLSTAT[Profit])/1000,FILTER((DBALLSTAT),DBALLSTAT[Eco_year]=Summary_hawb_prev),FILTER(ALL(Group_Logic),Group_Logic[Load Type] ="HAWB"))) return Summary_hawb_prev

Hi @sakshikaul ,

Modify the measure PrevYear1_HAWB:

PrevYear1_HAWB = 
var Summary_hawb_prev = MAXX(ALL(DBALLSTAT),DBALLSTAT[Eco_year])-1 
var summary_hawb_prevB = 
  If(
    SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
    CALCULATE(
      SUM(DBALLSTAT[Profit])/1000,
      FILTER(
        (DBALLSTAT),
        DBALLSTAT[Eco_year] = Summary_hawb_prev
      ),
      FILTER(
        ALL(Group_Logic),
        Group_Logic[Load Type] = "HAWB"
      )
    ) 
  ) 
return Summary_hawb_prev

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

HI,

If I am not selecting any year then I am getting the correct result but if I am selecting any year then I am not getting the result...I want on selection of year and non selection of year (both) I want values for current year and previous year. 

for eg- if I selected year=2018 then the values for previous year should also reflect like 2018 and 2017( previous year)

and if I am not selecting any year then values of max (year) and max(year)-1 should be reflected in graph( this is working fine now)

On selection of year=2021 not getting the desired result ie values for 2020 should also be reflected in graph

sakshikaul_0-1616561219332.png

sakshikaul_1-1616561320010.png

If I not selecting any year getting correct result

sakshikaul_3-1616561580428.png

 

 

 

Hi @sakshikaul ,

The Year field you put in the slicer should come from a separate table. Because if you use DBALLSTAT[Eco_year], then you choose 2021, only the 2021 data will be filtered out.

 

You can refer to the following sample data for modification.

v-kkf-msft_0-1616566075005.png

 

Measure = 
var MaxYear = MAXX(ALL('Table'),'Table'[year])
var SelectYear = 
    CALCULATE(
        SUM('Table'[value]),
        FILTER(
            'Table',
            'Table'[year] in { ALLSELECTED(Slicer[Year]), ALLSELECTED(Slicer[Year])-1 }
        )
    )
var NotSelect = 
    CALCULATE(
        SUM('Table'[value]),
        FILTER(
            'Table',
            'Table'[year] in { MaxYear, MaxYear-1 }
        )
    )
return 
    IF(ISFILTERED(Slicer),SelectYear,NotSelect)

 

v-kkf-msft_1-1616566102251.png     image.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

You want me to create duplicate of DBALLSTAT[Eco_year] for slicer?

and also,

if I am suppose to create duplicate of dballstat(eco_year)  for slicer with the table name ecoYeartable

then,
Measure =
var MaxYear = MAX(ALL('ecoYeartable'),'ecoYeartable'[year])
var SelectYear =
CALCULATE(
SUM('Table'[value]),----> which value ?? 

CALCULATE(
SUM(DBALLSTAT[Profit])/1000, FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB",

FILTER(
'Table',
'Table'[year] in { ALLSELECTED(Slicer[Year]), ALLSELECTED(Slicer[Year])-1 }
)
)
var NotSelect =
('CALCULATE(
SUM(DBALLSTAT[Profit])/1000,),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB",

FILTER(
'Table',
'Table'[year] in { MaxYear, MaxYear-1 }
)
)
return
IF(ISFILTERED(Slicer),SelectYear,NotSelect)

 

THIS IS HOW THE EXPRESSION WILL BE WRITTEN ?

 

Hi,

below measure is also giving me an error...please help?

 

Measure =
var MaxYear = MAXX(ALL('DBALLSTAT'),'DBALLSTAT'[Eco_year])
var SelectYear =
If(
SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
CALCULATE(
SUM(divide(DBALLSTAT[Profit]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in {ALLSELECTED(Slicer[Year]),ALLSELECTED(Slicer[Year])-1}
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB",
SUM(DBALLSTAT[CBM]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in {ALLSELECTED(Slicer[Year]),ALLSELECTED(Slicer[Year])-1}
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB",
)
)
)
var NotSelect =
If(
SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
CALCULATE(
SUM(DBALLSTAT[Profit])/1000,
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"
)
)
)
return
IF(ISFILTERED(Slicer),SelectYear,NotSelect)

I am not suppose to give a seperate calender in UI design. I want on selection of any Year... data for that selected year and corresponding previous year should get reflected in chart ie if current year selected= 2020 then current year and previous year =2019 data should be reflected in the chart 

 

and by default if nothing is selected then data for max(year) and max(year)-1 should be selected...

 

Hi @sakshikaul ,

I understand what you think. But in desktop, the slicer will filter the data in the same table.

That is, if you use DBALLSTAT[Eco_year] as the value of the slicer, when you select 2021, the desktop will first filter out the rows with the value of 2021 in the column Eco_year in the DBALLSTAT table. The measures you create will be calculated based on the filtered rows, which is why the data in 2020 will not be displayed when you choose 2021.

Hi @sakshikaul ,

Try this formula:

Measure = 
var MaxYear = MAXX(ALL('DBALLSTAT'),'DBALLSTAT'[Eco_year])
var SelectYear = 
    If(
        SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
        CALCULATE(
            SUM(DBALLSTAT[Profit])/1000,
            FILTER(
               DBALLSTAT,
               DBALLSTAT[Eco_year] in {ALLSELECTED(Slicer[Year]),ALLSELECTED(Slicer[Year])-1}
            ),
            FILTER(
                Group_Logic,
                Group_Logic[Load Type]="HAWB"
            )
        )
    )
var NotSelect = 
    If(
        SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",
        CALCULATE(
            SUM(DBALLSTAT[Profit])/1000,
            FILTER(
               DBALLSTAT,
               DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
            ),
            FILTER(
                Group_Logic,
                Group_Logic[Load Type]="HAWB"
            )
        )
    )
return 
    IF(ISFILTERED(Slicer),SelectYear,NotSelect)

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

sakshikaul_0-1616572586408.png

Still not getting the output.. getting following above  error 

 

Hi @sakshikaul ,

Change the type of column Slicer[Year] to the same type as column DBALLSTAT[Eco_year].

so for this can I simply duplicate the column in same table ?

Hi @sakshikaul ,

Yes, you can quickly select a column to copy in the Query Editor, and then put it in the Slicer table. It should be noted that after you create the Slicer table, make sure that it has no relationship with the DBALLSTAT table, and the Year column in Slice table has the same type as the Eco_year column in DBALLSTAT table.

v-kkf-msft_0-1616573490226.png

 

Like I have created two seperate expressions for previous and current year... so shouuld I write following code in single expression now?

Measure =
var MaxYear = MAXX(ALL('Table'),'Table'[year])
var SelectYear =
CALCULATE(
SUM('Table'[value]),
FILTER(
'Table',
'Table'[year] in { ALLSELECTED(Slicer[Year]), ALLSELECTED(Slicer[Year])-1 }
)
)
var NotSelect =
CALCULATE(
SUM('Table'[value]),
FILTER(
'Table',
'Table'[year] in { MaxYear, MaxYear-1 }
)
)
return
IF(ISFILTERED(Slicer),SelectYear,NotSelect)

 

I have cretaed two seperate measure for current and previous year... so should I write only one expression now?

sakshikaul_0-1616574944940.png

 

Hi @sakshikaul ,

I think creating one is enough. like this:

tempsnipdf.png

 

Hi,

I am facing a major issue like if  I am adding more than one measure( ie GP,Volume and nd yeild) in a chart it is getting automatically added in a tooltip and then selecting GP, on axis- month, I am not able to add legend as Eco year in that case,

Please check below image :-

I am able to add only one measure. On adding 2nd measure it is automatically getting added in a tooltip. How to add all the three measures in one chart?

sakshikaul_0-1616584886001.png

 

but if trying to add 2nd measure ie for volume then not able to add eco year as legend 

sakshikaul_1-1616584967302.png

 

Hi @sakshikaul ,

What you mean is that when GP is selected, the output is all normal. However, when Volume or Yield is selected, a null value is output. In this case, I suggest you create another measure according to the following formula, and then put it into the Values pane.

Measure = 
    SWITCH(
        SELECTEDVALUE('Summary Field Selection'[Field Value]),
        "GP",[MaxYear1_HAWB],
        "Volume",[MaxYear2_HAWB],
        "Yield",[MaxYear3_HAWB]
    )

v-kkf-msft_0-1616636393566.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

Hi, 

Now its working fine after adding above mentioned measure but now if I am selecting dballstat(eco_year)=2021...its not giving me previous year output...

sakshikaul_0-1616649532461.png

But if I am selecting slicer(eco_year)= 2021 then its showing me correct output

sakshikaul_1-1616649804932.png

but I want there should be only single calender ie dblstat(eco_year)  for selection of the year

 

Hi @sakshikaul ,

Unfortunately, as I said before, if you use dblstat(eco_year) as the value of the slicer, it will only display the data for the year you selected. This cannot be changed by writing DAX.

If you want it to display data for the selected year and the previous year, you must use slicer(eco_year).

I have a question. If you want the line chart to display data for 2 years, which year of data do other visuals display, such as the following.

v-kkf-msft_0-1616653042764.png

Best Regards,
Winniz

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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