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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

For other visuals I am using dballlstat(eco_year).  This is the reason I cannot have two seperate calenders in one report.

Can this be replaced by using previousYear function?

 

and also , for yeild I have a following expression 

If(SELECTEDVALUE('Summary Field Selection'[Field Value])="Yield", DIVIDE(CALCULATE(SUM(DBALLSTAT[Profit]),FILTER(DBALLSTAT,DBALLSTAT[Eco_year]=MAX(DBALLSTAT[Eco_year])),FILTER(Group_Logic,Group_Logic[Load Type]="HAWB")),CALCULATE(SUM(DBALLSTAT[ChglWt(KG)]),FILTER(DBALLSTAT,DBALLSTAT[Eco_year]=MAX(DBALLSTAT[Eco_year])),FILTER(Group_Logic,Group_Logic[Load Type]="HAWB")),0))

 I am trying to write above expression in the dax provided by you I am getting an error. Please help 

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)

 

 

Hi @sakshikaul ,

You come up with a great idea, I test it and it worked.
Based on the previous discussion, create the following measure:

SelectYear = 
    SWITCH(
        SELECTEDVALUE('Summary Field Selection'[Field Value]),
        "GP",[MaxYear1_HAWB],
        "Volume",[MaxYear2_HAWB],
        "Yield",[MaxYear3_HAWB]
    )
previous year = 
    CALCULATE(
        [SelectYear],
        FILTER(
            ALL('DBALLSTAT'),
            'DBALLSTAT'[Eco_year] = MAX('DBALLSTAT'[Eco_year])-1
            && 'DBALLSTAT'[Month] = MAX('DBALLSTAT'[Month])
        )
    )

v-kkf-msft_0-1616656567699.png

Using this method, you don't need to calculate the previous year's value separately for different field values.

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

Here in this expression select_year is giving me an error 

sakshikaul_0-1616658738524.png

 

Following expression is giving me an error when I am trying to apply formula for yeild. Please  Chelp in resolving the issue and  MEANWHILE i WILL TRY CREATING PREVIOUS YEAR DAX AS YOU SUGGESTED-

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

fOLLOWING IS THE iMAGE ATTACHED 

 

sakshikaul_1-1616658039211.png

 

Hi @sakshikaul ,

Try this formula:

 

 

MaxYear3_HAWB_Gp/Vol =
var MaxYear = MAXX(ALL('DBALLSTAT'),'DBALLSTAT'[Eco_year])
var Select_Year =
If(
or(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume"),
DIVIDE(CALCULATE(SUM(DBALLSTAT[Profit]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] = max('DBALLSTAT'[Eco_year])
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB")),
CALCULATE(SUM(DBALLSTAT[ChglWt(KG)]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] = max('DBALLSTAT'[Eco_year])
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"),0
)
)
)
var NotSelect =
If(
or(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume"),
DIVIDE(CALCULATE(SUM(DBALLSTAT[Profit]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB")),
CALCULATE(SUM(DBALLSTAT[ChglWt(KG)]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"),0
)
)
)
return
IF(ISFILTERED('DBALLSTAT'[Eco_year]),Select_Year,NotSelect)

 

 

 

The SelectYear referenced in measure previous year is the previously created measure.

v-kkf-msft_0-1616665242648.png

v-kkf-msft_1-1616665408617.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,

Still getting an error in following expression 

MaxYear3_HAWB_Gp/Vol = var MaxYear = MAXX(ALL('DBALLSTAT'),'DBALLSTAT'[Eco_year])
var Select_Year =
If(
or(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume"),
DIVIDE(CALCULATE(SUM(DBALLSTAT[Profit]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] = max('DBALLSTAT'[Eco_year])
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB")),
CALCULATE(SUM(DBALLSTAT[ChglWt(KG)]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] = max('DBALLSTAT'[Eco_year])
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"),0
)
)
)
var NotSelect =
If(
or(SELECTEDVALUE('Summary Field Selection'[Field Value])="GP",SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume"),
DIVIDE(CALCULATE(SUM(DBALLSTAT[Profit]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB")),
CALCULATE(SUM(DBALLSTAT[ChglWt(KG)]),
FILTER(
DBALLSTAT,
DBALLSTAT[Eco_year] in { MaxYear, MaxYear-1 }
),
FILTER(
Group_Logic,
Group_Logic[Load Type]="HAWB"),0
)
)
)
return
IF(ISFILTERED('DBALLSTAT'[Eco_year]),Select_Year,NotSelect)

sakshikaul_0-1616691290880.png

 

Hi @sakshikaul ,

I create some sample data and then create the following measures.

MaxYear3_HAWB_Gp/Vol = 
var Select_Year =
    If(
        SELECTEDVALUE('Summary Field Selection'[Field Value]) = "GP"||SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume",
        CALCULATE(
            DIVIDE(SUM(DBALLSTAT[Profit]),SUM(DBALLSTAT[ChglWt(KG)])),
            FILTER(
                DBALLSTAT,
                DBALLSTAT[Eco_year] = max('DBALLSTAT'[Eco_year])
            ),
            FILTER(
                Group_Logic,
                Group_Logic[Load Type]="HAWB"
            )
        )
    )
var NotSelect =
    If(
        SELECTEDVALUE('Summary Field Selection'[Field Value])="GP"||SELECTEDVALUE('Summary Field Selection'[Field Value])="Volume",
        CALCULATE(
            DIVIDE(SUM(DBALLSTAT[Profit]),SUM(DBALLSTAT[ChglWt(KG)])),
            FILTER(
                DBALLSTAT,
                DBALLSTAT[Eco_year] = MAXX(ALL('DBALLSTAT'),'DBALLSTAT'[Eco_year])
            ),
            FILTER(
                Group_Logic,
                Group_Logic[Load Type]="HAWB"
            )
        )
    )
return 
    IF(ISFILTERED('DBALLSTAT'[Eco_year]),Select_Year,NotSelect)
SelectYear = 
    SWITCH(
        SELECTEDVALUE('Summary Field Selection'[Field Value]),
        "GP",[MaxYear3_HAWB_Gp/Vol],
        /*"Volume",[MaxYear2_HAWB],*/
        "Yield",[MaxYear3_HAWB_Gp/Vol]
    )
previous year = 
    CALCULATE(
        [SelectYear],
        FILTER(
            ALL('DBALLSTAT'),
            'DBALLSTAT'[Eco_year] = MAX('DBALLSTAT'[Eco_year])-1
            && DBALLSTAT[Month] = MAX(DBALLSTAT[Month])   
        )
    )

v-kkf-msft_0-1616729364536.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 

As discussed earlier also, I am getting the result but I want if dballstat(eco_year)= 2021 selecte then the data should be shown for complete 2020 ie ( jan to dec ) and for 2021( jan to feb).

Here you can check in below image only data for 2021 jan n feb, 2020 Jan n feb is being captured. I need for 2020 ( jan to dec hould be captured)

sakshikaul_0-1616737315985.png

 

Hi @sakshikaul ,

Modify the measure:

previous year = 
var Selectvalue =    
CALCULATE(
        [SelectYear],
        FILTER(
            ALL('DBALLSTAT'),
            'DBALLSTAT'[Eco_year] = MAX('DBALLSTAT'[Eco_year])
            && 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(DBALLSTAT[Month])
        )
    )
return IF(ISFILTERED('DBALLSTAT'[Eco_year]),Selectvalue,notselect)

v-kkf-msft_0-1616741072460.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,

If I am writing above expresssion again I am not getting previous Year comparison in chart and also I am not getting the correct value.

 

sakshikaul_0-1616750301244.png

I am not geeting the correct value. If I am not selecting any year then also I am getting value for 2021 march which is not correct. I have data for 2021 for jan and feb only.

sakshikaul_1-1616750459359.png

 

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.

Hi 

, I am getting an expected output if I am selecting year=2021 as shown below

sakshikaul_1-1617134585051.png

 

 

.... but my requirement was I want if I select year =2020 then I want the comparison for current year and previous year

( basically I want on dynamic selection - whichever year user will select the data should be reflected for the selected year and one year previous to the currently selected year ) In below case if I select year=2020 then only 2020 data is shown, whereas data for 2019 should also be displayed.   please help

 

sakshikaul_0-1617134560026.png

 

Hi @sakshikaul ,

Yes. My previous reply gave the output you expected.

image.pngimage.png

Please see Message 33 for details.

v-kkf-msft_0-1617152945371.png

Best Regards,
Winniz

Hi,

I am getting an expected output if I am selecting year=2021 as shown below....

sakshikaul_0-1617124161100.png

 

but if I want if I select year =2020 then I want the comparison for current year anr previous year ( basically I want on dynamic selection - whichever year user will select the data should be reflected for the selected year and one year previous to the currently selected year )

In below case if I select year=2020 then only 2020 data is shown, whereas data for 2019 should also be displayed.

 

sakshikaul_1-1617124406511.png

 

HI, 

It is working fine if I am selecting year as 2021 but its again not working correctly if I am selecting year=2020

Here I am not getting previous year comparison. Previous year comparison is only functinable if I select year =2021

 

So Now i want if I select year =2021 then the data for 2021 and 2020 should be available 

simmilarly if I select  year=2020 then the data for 2020 and 2019 should be available on the graph as  so on....

sakshikaul_0-1616745178054.png

 

HI,

Its working fine now... but here in Previous year measure (2020) its showing data for only last two months whereas 2020 should show complete data from jan 2020 - dec 2020.. Plesae help

sakshikaul_0-1616668331863.png

 

Firstly If I am not selecting any year filter [ie dballstat(year)] then I am getting correct value as shown in mage 

sakshikaul_0-1616578571476.png

But when I am selecting dbalstat(eco_year)= 2021 the I am getting values for that year only as shown in below :-

sakshikaul_1-1616578775988.png

 

Third thing is that if I am taking  only one measure , on axis-month, legend as eco_year then, selecting - volume with no eco year filter(no year is selected) then  I am getting correct value 

as shown below:-

sakshikaul_2-1616579683929.png

but if I am adding more than one measure in a chart it is getting automatically added in a tooltip and then selecting GP, on axis- month, legend- year, I am not getting value for GP

shown below

sakshikaul_3-1616580055789.png

 

please help 

 

Hi @sakshikaul ,

If your report does not contain sensitive data, can you share your report? It will help us solve the problem faster.

Best Regards,
Winniz

No, I cant share my application as its containing comapny's data. 

I am very close to the solution. I just want now Previous year measure (2020) its showing data for only last two months whereas 2020 should show complete data from jan 2020 - dec 2020.. Plesae help

sakshikaul_0-1616675629908.png

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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