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.
Hello,
I am trying to port a Tableau 2020 solution to Power BI and I have a lot of Tableau Calculated Fields that I need to convert to Power BI / DAX. Here is one that is looking for a match on a specific table column for the following list of URLs and if a match, it will aggregate the total Pageviews, which is another column in the table. Here is the table sample :
Date | PagePath | PageViews
8-1-2020 | www.banhealth.com | 4
8-2-2020| banhealth.com | 2
8-3-2020 | tacobell.com | 0
8-4-2020 | healthorg.com | 1
TotalPageViews =
IF STARTSWITH([ga:pagePath], "banhealth.com")
OR STARTSWITH([ga:pagePath], "www.banhealth.com")
OR STARTSWITH([ga:pagePath], "banhealth.com")
OR STARTSWITH([ga:pagePath], "banhealth.mediaroom.com")
THEN [Pageviews]
ELSE 0
END
In the example above, TotalPageViews will have a total = 6 based on the logic above. I am trying to do the same in DAX/Power BI but not working using a New Measure and a New Column gives me all zeros in the column. I just need a calculated single field that calculates all records on the fly and gives me a total.
I tried the following but doesnt work the way i need it. Here is an example with a single URL.
NewColumn = IF(LEFT(GA_Consolidated[pagePath], LEN("banhealth.com")) = "banhealth.com",SUM(GA_Consolidated[pageviews]), 0)
Thank you so much for your time and help with this.
Solved! Go to Solution.
Hi @Anonymous ,
Create 2 measures as below:
_check =
IF (
MAX ( 'Table'[ PagePath ] )
IN {
"banhealth.com",
"www.banhealth.com",
"banhealth.com",
"banhealth.mediaroom.com"
},
SUM ( 'Table'[ PageViews] ),
0
)
Measure = SUMX(VALUES('Table'[ PagePath ]),[_check])
Or a column as below:
Column =
IF('Table'[ PagePath ]
IN {
"banhealth.com",
"www.banhealth.com",
"banhealth.com",
"banhealth.mediaroom.com"
},
'Table'[ PageViews],0
)
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
@Anonymous , You can use switch for that
Switch( True() ,
LEFT(GA_Consolidated[pagePath], LEN("banhealth.com")) = "banhealth.com",SUM(GA_Consolidated[pageviews]),
LEFT(GA_Consolidated[pagePath], LEN("www.banhealth.com")) = "www.banhealth.com",SUM(GA_Consolidated[pageviews]),
0)
refer if needed
Switch-Case statement of #PowerBI: https://www.youtube.com/watch?v=gelJWktlR80&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=56
Thank you very much for your response! I am getting the same results where I get the TOTAL pageviews for ALL records and not just for those that match the list of URLs. Right now what I need is to ONLY count the pageviews for those records where the PagePath starts with the URLs listed.
Thanks again!
Hi @Anonymous ,
Create 2 measures as below:
_check =
IF (
MAX ( 'Table'[ PagePath ] )
IN {
"banhealth.com",
"www.banhealth.com",
"banhealth.com",
"banhealth.mediaroom.com"
},
SUM ( 'Table'[ PageViews] ),
0
)
Measure = SUMX(VALUES('Table'[ PagePath ]),[_check])
Or a column as below:
Column =
IF('Table'[ PagePath ]
IN {
"banhealth.com",
"www.banhealth.com",
"banhealth.com",
"banhealth.mediaroom.com"
},
'Table'[ PageViews],0
)
And you will see:
For the related .pbix file,pls see attached.
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
THank you very much!
Hi @Anonymous ,
Glad to help.
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
93 | |
77 | |
65 | |
53 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |