I have not been able to find an answer to this question, although there are some similar ones.
I have a large dataset (9 million rows) that contains
an id column ("id"),
an identifier if "id" is new for that period ("new_id"),
a latitude column ("lat")
and a longitude column ("long").
In SAS, what I want to do is, using the geodist function, compare the distance between each row and create an indicator, "nearby", that equals 1 if the distance between that id and any other id is less than 50 miles and "new_id" = 1 for the other row.
Below is some pseudo code of what I'm trying to do. Any help would be greatly appreciated. Thanks!
Pseudo code:
For all_rows1 in data
For all_rows2 in data
if (geo_dist(all_rows1(lat), all_rows1(long), all_rows2(lat), all_rows2(long) < 50)
and all_rows2(new_id) = 1
then all_rows1(nearby) = 1
Related
Im trying to add just a simple rank numbering or row number to column but no luck.
I have a simple test table which consist of 2 columns - Name and Room number. I have attached Room Number to filter so it can be filtered. My goal is to add a number to resulted raws. Im using dax measure for this but no luck. This is my DAX measure code:
Visitor num = RANKX('myTab',CALCULATE(count('myTab'[Name])))
But it returns only 1 for each row
My PBIX file
Try changing the filter context:
Visitor num = RANKX(ALLSELECTED('myTab'),CALCULATE(MAX('myTab'[Name])))
I'm "bugging" to transform my datas to something usable.
For the moment, a datasource provides me a table where a column contains dates, following by 24 columns representing each hours. In this 24 columns, for each date (each row) I've a total of phone calls.
I want to show the hourly repartition. So, my original datasource is not really usable ans need to transform it with something where there is a column "hour" (a simple index from 0 to 23 or 1 to 24) and a column with the total call for each column from the original column. But I'm a lot confused to do it because I don't have a way to create a relationship. Like this :
Someone have any idea to help me? Thanks in advance
I would unpivot the data source and then create two dimensions (Calendar) and (Time).
I am trying to create a calculated table in Power BI that will provide one row per person based on the most earliest date that the score column is greater than 9. The initial table is thousands of rows and includes multiple entries per person if more than one score was collected.
Initial table:
Output goal:
Since Supergirl didn't ever have a score > 9, she isn't included in the output. Each person with a score > 9 will have one row with the score that occurred on the first date that the score was > 9 and the Date Completed.
I will then add columns and measures based on this new table. I tried using the summarize function and duplicating the initial table and manipulating it without success and have read many posts and didn't find anything that matched my ask. Please help :)
you could start off with creating an additional calculated column "TenOrMore" where you would simply calculate if Score >= 10 then true else false. Then your next select you can do max or min on the score where column "TenOrMore" is true or select all the values and calculate the next step. I hope this helps.
I have a table with country and population for 2017, and I have another table with country and population growth rate%. And I have one table with years like (2018 to 2028). I am trying to find calculated population for 10 years on the basis of these data as we are calculating compound interest.
Because you are working with growth rates, it is very unlikely that you will want to do this calculation as a measure. Rates don't aggregate well.
So, the first thing you're going to want to do is get your data into one table. I would do this in query editor.
You'll need a Cartesian join between your list of countries and a list of years. The PowerBI method for this is a little non-intuitive. You add a custom column, and in the formula you just type in the name of the table.
The result is that every single row in the countries table will be matched with every single row from the years table. If you have 5 rows in one and 10 rows in the other, the resulting table is 50 rows.
Then Merge in your table with the growth rates. Now you have a table that has the name of the country, the 2017 starting population, the growth rate. This set of rows will be repeated for every year from 2018 - 2028.
There is a specific formula for cumulative (compounded) growth.
Pricipal * ( 1 + RatePerPeriod / NumberOfCompoundsPerPeriod) ^ (NumberOfPeriods * NumberOfCompoundsPerPeriod)
You're doing this annually, so it simplifies a bit
Pricipal * ( 1 + Rate) ^ (NumberOfYears)
And the M will look like this:
[2017 Population] * Number.Power((1 + [Growth]),([Year] - 2016))
Good Luck! Hope it helps.
I am working on powerbi, using data over 2 months period, writing dax queries and trying to build reports.
I am trying to show the monthly values in cards visuals.
And i am able to do it using the measure below.
Sample Data:-
PlanPrevMon = CALCULATE([PlanSum],PREVIOUSMONTH('Month Year'[Date]))
CustomKPI = IF(ISBLANK([PlanSum]),"No Data Available ",[PlanSum])&" "&IF([PlanSum]=[PlanPrevMon],"",IF([PlanSum] > [PlanPrevMon],UNICHAR(8679),UNICHAR(8681))&IF([PlanSum]<=0,"",""))
But here i don't want user to choose the month values from slicer.
I would like to show the card values as
if current month value is not available then it should compare with the previous month value automatically as shown in an image below
For example, Apr-2017 value is not available; in this scenario I would like it to compare with the Mar-2017 value.
If Mar-2017 value also not available, then the previous month value and so on
Edit
I tried what #user5226582 suggested but still getting wrong values as below image.
As you can see i restricted to crosscheck whether the value is getting in a right way of not.
But not.
This is the measure i have used as #user5226582 suggested.
c =
var temp = 'Revenue Report'[Date]
return CALCULATE(LASTNONBLANK('Revenue Report'[Planned Rev],
'Revenue Report'[Planned Rev]),
ALL('Revenue Report'),
'Revenue Report'[Date]<=temp)`
Can you please correct me if i am doing anything wrong
Does this help...?
To get the PlanPrevMon column to show like this, I first created a new index column:
id = COUNTROWS(FILTER(Sheet1, EARLIER(Sheet1[Date],1)>Sheet1[Date]))
Then I used the index to help create the PlanPrevMon column in two steps:
Step 1: I made one column named PlanPrevMon1.
PlanPrevMon1 = SUMX(FILTER(Sheet1,Sheet1[id]=EARLIER(Sheet1[id])-1),Sheet1[PlanSum])
Step 2: I made another column named PlanPrevMon.
PlanPrevMon = if(ISBLANK(Sheet1[PlanPrevMon1]),
if(Sheet1[id]=1,0,CALCULATE(LASTNONBLANK(Sheet1[PlanPrevMon1],Sheet1[PlanPrevMon1]),ALL(Sheet1),ISBLANK(Sheet1[PlanSum]))),
Sheet1[PlanPrevMon1])
For the card, I used this measure:
Card = CALCULATE(LASTNONBLANK(Sheet1[PlanPrevMon],1),FILTER(Sheet1,Sheet1[id]=max(Sheet1[id])))
I hope this helps.
You can use LASTNONBLANK DAX function.
Example data:
a b
1 1
2
3 2
4
5 3
Calculated column:
c =
var temp = Table1[a]
return CALCULATE(LASTNONBLANK(Table1[b],Table1[b]),ALL(Table1),Table1[a]<=temp)
Results in:
a b c
1 1 1
2 1
3 2 2
4 2
5 3 3