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
PowerOn_DP
Helper I
Helper I

Top 6 + Other for each month

Hi,

 

I am right on my first power BI report, trying to build SSRS version in pbi.

 

Please check below supported datasets 

 

1] Data looks like below in actual table

 

FirstContactOnClub_CodeLocationSource_TypeNew_Prospect_IDSTART_ONARCHIVED
01-12-20208608Colchester AGCO     Online Membership Enquiry112-11-20121753-01-01
01-12-20208610Edgbaston AGED      Online Guest Pass201-03-20131753-01-01
01-12-20208625Dun Laoghaire       Google201-09-20131753-01-01
01-12-20208633High Wycombe        Social Media122-02-20141753-01-01
01-12-20208636Stratford           Online Membership Enquiry115-05-20171753-01-01
01-12-20208636Stratford           Web site115-05-20171753-01-01
01-12-20208639Telford             Friend Or Family301-05-20141753-01-01
01-12-20208639Telford             Online Membership Enquiry101-05-20141753-01-01
01-12-20208644Kensington          Web site101-11-20141753-01-01
01-12-20208647Clapham SouthAGCS   Facebook101-11-20141753-01-01
01-12-20208650Ilkeston            Corporate Deal113-04-20151753-01-01
01-12-20208655Gosport AGGP        Facebook201-06-20151753-01-01
01-12-20208660Bicester AGBC       Online Guest Pass210-08-20151753-01-01
01-12-20208663Tooting             Web site125-11-20151753-01-01
01-12-20208677Grantham            Online Guest Pass105-09-20161753-01-01
01-12-20208678Trowbridge          Friend Or Family116-01-20161753-01-01
01-12-20208678Trowbridge          Online Membership Enquiry216-01-20161753-01-01
01-12-20208692Dalston             Online Guest Pass112-10-20181753-01-01
01-12-20208709Worthing            Online Membership Enquiry101-02-20171753-01-01
01-12-20208733Letchworth          Online Membership Enquiry105-12-20161753-01-01
01-12-20208745Swansea             Referral105-12-20161753-01-01
01-12-20208755Chorley             None102-01-20171753-01-01

 

2] For the SSRS, I had a sql code using which I had returned below output for my chart 

 

DatefromMonthYearRnSource_TypeNew_Prospects
01-11-2020Nov-201Online Membership Enquiry881
01-11-2020Nov-202Leaflet786
01-11-2020Nov-203Online Guest Pass495
01-11-2020Nov-204Friend Or Family447
01-11-2020Nov-205None383
01-11-2020Nov-206Facebook380
01-11-2020Nov-207Other1312
01-12-2020Dec-201Online Guest Pass2763
01-12-2020Dec-202Online Membership Enquiry2202
01-12-2020Dec-203Friend Or Family1726
01-12-2020Dec-204None1524
01-12-2020Dec-205Web site761
01-12-2020Dec-206A Friend719
01-12-2020Dec-207Other6118

 

Now as I had this resultset, it was easy to create a stacked bar chart by putting source type on axis and sum up New prospects for each month like below 

 
 

Capture.PNG

 

Now, If I want you to walk through the sql where I am creating rank and the Other group with all the source types coming after Rn=6 

 

Capture1.PNG

 

Coming back to Power Bi, I have added the table which is showing in point 1]

I have Club and Calender master tables in relationships to have slicer on Club_Code and FirstContactOn 

 

Now, I have tried summarize table using dax, measures, calculated columns and so many things to group the data using Source type and sum New_Prospects_ID for each month calculated using FirstContactOn,  but I am not able to get the expected data with transformation in power bi shows in point 2] 

 

Its been 2 days but it just makes me confused after trying many things and thus still standing at the same page. 

 

Please any help would be appreciated. Please ask for any supporting script if needed.

 

Thanks in advance! 

   

 

 

 

 

 

2 ACCEPTED SOLUTIONS

Hi @PowerOn_DP ,

Here is formula to rank Sum of New_Prospect_ID grouped by FirstContactOn and SourceType.

Rank NewProspectID by Source_Type and FirstContactOn =
VAR RankProspectsBySource =
    RANKX (
        ALL ( 'Prospects' ),
        CALCULATE (
            SUM ( 'Prospects'[New_Prospect_ID] ),
            ALLEXCEPT ( 'Prospects', 'Prospects'[Source_Type], 'Prospects'[FirstContactOn] )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( RankProspectsBySource <= 6RankProspectsBySource7 )

ALLEXCEPT (dax) = GROUP BY (sql)
RankX = in expression it should be some calculation if needs summarized version, not only column name

Rankx.PNG

Regards,
Nemanja Andic

View solution in original post

Icey
Community Support
Community Support

Hi @PowerOn_DP ,

 

How about creating a calculated column like below?

Rabk TopN+Other =
VAR RankProspectsbySource =
    RANKX (
        FILTER (
            Prospects,
            Prospects[FirstContactOn] = EARLIER ( Prospects[FirstContactOn] )
        ),
        CALCULATE (
            SUM ( Prospects[New_Prospect_ID] ),
            ALLEXCEPT ( Prospects, Prospects[Source_Type], Prospects[FirstContactOn] )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( RankProspectsbySource <= 6, RankProspectsbySource, 7 )

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

View solution in original post

5 REPLIES 5
Icey
Community Support
Community Support

Hi @PowerOn_DP ,

 

How about creating a calculated column like below?

Rabk TopN+Other =
VAR RankProspectsbySource =
    RANKX (
        FILTER (
            Prospects,
            Prospects[FirstContactOn] = EARLIER ( Prospects[FirstContactOn] )
        ),
        CALCULATE (
            SUM ( Prospects[New_Prospect_ID] ),
            ALLEXCEPT ( Prospects, Prospects[Source_Type], Prospects[FirstContactOn] )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( RankProspectsbySource <= 6, RankProspectsbySource, 7 )

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

PowerOn_DP
Helper I
Helper I

Hi,

I tried Rankx with if condition to just see how the rank will be generated for my Source Type based on Total of New_Prospects_Id

 

Capture.PNG

 

Now, I just picked up Rank TopN+other into table with Source category and one measure (Does sum of New Prospects ID)

 

Capture1.PNG

Can you please help me why the rank looks weird

 

Hi @PowerOn_DP ,

Here is formula to rank Sum of New_Prospect_ID grouped by FirstContactOn and SourceType.

Rank NewProspectID by Source_Type and FirstContactOn =
VAR RankProspectsBySource =
    RANKX (
        ALL ( 'Prospects' ),
        CALCULATE (
            SUM ( 'Prospects'[New_Prospect_ID] ),
            ALLEXCEPT ( 'Prospects', 'Prospects'[Source_Type], 'Prospects'[FirstContactOn] )
        ),
        ,
        DESC,
        DENSE
    )
RETURN
    IF ( RankProspectsBySource <= 6RankProspectsBySource7 )

ALLEXCEPT (dax) = GROUP BY (sql)
RankX = in expression it should be some calculation if needs summarized version, not only column name

Rankx.PNG

Regards,
Nemanja Andic

PowerOn_DP
Helper I
Helper I

Hi @nandic 

 

Thanks for sharing, I will check it and see if they can be of any help in custimizing.

nandic
Memorable Member
Memorable Member

Hi @PowerOn_DP ,

At this moment i can't provide final solution, but here are great examples how to make it and hope it will help you figure out the logic and if need to customize to your scenario:
1) Curbal: https://www.youtube.com/watch?v=UAnylK9bm1I (uses calculated column, so rank will be static - it will not change based on slicers change)
2) SQLBI: https://www.sqlbi.com/articles/showing-the-top-5-products-and-others-row/ (uses measure so it will be dynamic if slicers change)
3) Community: https://community.powerbi.com/t5/Desktop/Top-N-and-others-at-the-same-time/td-p/493040 (uses also measure)

Regards,
Nemanja Andic

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.